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 | 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 June 7th, 2007, 05:08 AM
Registered User
Join Date: Aug 2004
Location: Delhi, , India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikingsunil
Default How to make a WMI call from an ASP.Net Page

Has anybody got any experience calling WMI from AP.Net page...? I am getting a strange problem when I am trying to make WMI calls from my ASP.Net page using the code given below, My website is configured to use the Windows Integrated Authentication and impersonation is ON. The IIS host server is allowed for delegation from the Active Directory settings, still I am getting these exceptions:

Access is denied.
at System.Management.ManagementScope.Initialize() at System.Management.ManagementObject.Initialize(Bool ean getObject) at System.Management.ManagementObject.InvokeMethod(St ring methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)

The code is as following:

ManagementPath path = new ManagementPath();
path.NamespacePath = "root\\CIMV2";

path.Server = txtMachine.Text; // User Supplied Machine Name essentially in the same windows domain.
path.RelativePath = string.Format("Win32_service.Name='{0}'", txtService.Text); //Formaing the Relative path with user supplied windows service name.
ManagementObject serviceManagementObject = new ManagementObject(path);
serviceManagementObject.InvokeMethod("StopService" ,null, null); //Trying to stop Windows Service

//Collecting Suppied machine's Storage media information
SelectQuery selectQuery = new SelectQuery("SELECT * FROM Win32_LogicalDisk");
using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(new ManagementScope(GetManagementPath(networkID)), selectQuery))
    ManagementObjectCollection driveMangementObjects = managementObjectSearcher.Get();

    //Drive[] drives = new Drive[driveMangementObjects.Count];
    //int i = 0;
    foreach (ManagementObject driveMangementObject in driveMangementObjects)
        String DriveType = driveMangementObject["DriveType"].ToString();
        String DeviceID = driveMangementObject["DeviceID"].ToString();

            long DriveSize = Convert.ToInt64(driveMangementObject["Size"]);
            long DriveFreeSpace = Convert.ToInt64(driveMangementObject["FreeSpace"]);

            //displaying the info on UI.
            if(lblDevices.Text =="")
                lblDevices.Text = lblDevices.Text + DeviceID + "<BR> Size: "+ DriveSize.ToString() + "<BR> Freespace :"+ DriveFreeSpace.ToString();
                lblDevices.Text = lblDevices.Text + "<BR>"+ DeviceID + "<BR> Size: "+ DriveSize.ToString() + "<BR> Freespace :"+ DriveFreeSpace.ToString();

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
Calling WMI from ASP.Net Web Page vikingsunil ASP.NET 1.0 and 1.1 Professional 1 June 28th, 2007 08:54 AM
Calling WMI from ASP.Net Web Page vikingsunil ASP.NET 1.0 and 1.1 Professional 0 June 7th, 2007 05:19 AM
running Wmi Scripts in ASP.NET Looney Javascript How-To 3 May 20th, 2005 01:30 PM
How can I call a vb.net Exe from an asp.net page? jorevil Classic ASP Basics 0 October 1st, 2003 11:34 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 06:14 AM.

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