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 June 7th, 2007, 05:08 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 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();

        if(Convert.ToInt64(DriveType)==3)
        {
            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();
            else
                lblDevices.Text = lblDevices.Text + "<BR>"+ DeviceID + "<BR> Size: "+ DriveSize.ToString() + "<BR> Freespace :"+ DriveFreeSpace.ToString();
        }
    }
}








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





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