How to call WMI from web service?
Hi,
I have trouble to call WMI from the web service.
The code is like the following:
==================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Management;
using System.Configuration;
namespace MyWMI
{
/// <summary>
/// Summary description for ADSSrv.
/// </summary>
///
public class MyWMI : System.Web.Services.WebService
{
public MyWMI()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod]
public string MyTest()
{
try
{
ManagementClass someClass = new ManagementClass("\\\\.\\root\\someclassname");
ManagementObject objDevice = someClass.CreateInstance();
// set device properties
objDevice["Name"] = "sample1.example.com";
objDevice["Description"] = "Sample device";
// create device instance
objDevice.Put();
return "success";
}
catch(Exception ex)
{
return ex.ToString();
}
}
}
}
=============================
I run this web service with WMI on the same server with Administrator privilage and I also add user ASPNET to the Administrator group.
But the web service return the following error message:
=======================================
System.Management.ManagemetException:
Access denied at System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStat atus errorCode) System.Management.ManagementObject.Put(PutOptions options) at System.Management.ManagementObject.Put() at MyTest()
========================================
Does anyone know what's wrong with the code?
Thanks,
|