Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 2nd, 2003, 03:27 PM
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call WMI from web service?


I have trouble to call WMI from the we 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



        #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)








        public string MyTest()




                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


                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:
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 wrone with the code?

Reply With Quote
  #2 (permalink)  
Old July 14th, 2003, 10:45 AM
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths

  Actually, it is more likely that this code is executing with the privlages of IUSR_MACHINENAME, IWAM_MACHINENAME, or some other such account. The default behavior when you create a connection object with a 0 object constructor is to instantiate with the credentials of the creating process.
   Try something like this ( assuming that the variables strUsername and strPassword have been set to the credentials you want to use; you can hard code these, or pass them in as parameters to the web service ... perhaps from a form on the web page)...

   ConnectionOptions oConn = new ConnectionOptions();
   oConn.Username = strUsername;
   oConn.Password = strPassword;
   System.Management.ManagementScope oMs = new System.Management.ManagementScope("\\\\" + strComputername + "\\root\\cimv2", oConn);


Meredith Shaebanyan

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web service call error Tomi J2EE 0 February 1st, 2008 06:22 AM
Web Service call fails gurujeet .NET Web Services 10 December 18th, 2006 06:28 PM
call web service from pocket pc rsa3des .NET Web Services 1 June 7th, 2006 07:41 AM
Call a Web Service deer_reema ASP.NET 1.0 and 1.1 Basics 1 April 28th, 2006 10:12 AM
How to call WMI from web service? yezh99 .NET Web Services 1 July 22nd, 2003 11:58 PM

All times are GMT -4. The time now is 10:47 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.