Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 June 7th, 2007, 05:19 AM
Registered User
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikingsunil
Default Calling WMI from ASP.Net Web 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();

Can anybody please tell how can I get this working ?

Thanks in Advance

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
How to make a WMI call from an ASP.Net Page vikingsunil VS.NET 2002/2003 0 June 7th, 2007 05:08 AM
calling a java servlet from a asp.net page dub_beat ASP.NET 2.0 Basics 0 April 2nd, 2007 08:31 PM
running Wmi Scripts in ASP.NET Looney Javascript How-To 3 May 20th, 2005 01:30 PM

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