Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 2nd, 2003, 03:27 PM
Registered User
Join Date: Jul 2003
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?

Old July 14th, 2003, 10:45 AM
Authorized User
Join Date: Jul 2003
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

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.