Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
System.Management Namespace

Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Applications and services can query for interesting management information (such as how much free space is left on the disk, what is the current CPU utilization, which database a certain application is connected to, and much more), using classes derived from ManagementObjectSearcher and ManagementQuery, or subscribe to a variety of management events using the ManagementEventWatcher class. The accessible data can be from both managed and unmanaged components in the distributed environment.

  ClassDescription
Public classCompletedEventArgsHolds event data for the Completed event.
Public classConnectionOptionsSpecifies all settings required to make a WMI connection.
Public classDeleteOptionsSpecifies options for deleting a management object.
Public classEnumerationOptionsProvides a base class for query and enumeration-related options objects.
Public classEventArrivedEventArgsHolds event data for the EventArrived event.
Public classEventQueryRepresents a WMI event query.
Public classEventWatcherOptionsSpecifies options for management event watching.
Public classInvokeMethodOptionsSpecifies options for invoking a management method.
Public classManagementBaseObjectContains the basic elements of a management object. It serves as a base class to more specific management object classes.
Public classManagementClassRepresents a Common Information Model (CIM) management class. A management class is a WMI class such as Win32_LogicalDisk, which can represent a disk drive, and Win32_Process, which represents a process such as Notepad.exe. The members of this class enable you to access WMI data using a specific WMI class path. For more information, see "Win32 Classes" in the Windows Management Instrumentation documentation in the MSDN Library at http://msdn.microsoft.com/library.
Public classManagementDateTimeConverterProvides methods to convert DMTF datetime and time intervals to CLR-compliant DateTime and TimeSpan format and vice versa.
Public classManagementEventArgsRepresents the virtual base class to hold event data for WMI events.
Public classManagementEventWatcherSubscribes to temporary event notifications based on a specified event query.
Public classManagementExceptionRepresents management exceptions.
Public classManagementNamedValueCollectionRepresents a collection of named values suitable for use as context information to WMI operations. The names are case-insensitive.
Public classManagementObjectRepresents a WMI instance.
Public classManagementObjectCollectionRepresents different collections of management objects retrieved through WMI. The objects in this collection are of ManagementBaseObject-derived types, including ManagementObject and ManagementClass. The collection can be the result of a WMI query executed through a ManagementObjectSearcher, or an enumeration of management objects of a specified type retrieved through a ManagementClass representing that type. In addition, this can be a collection of management objects related in a specified way to a specific management object - in this case the collection would be retrieved through a method such as GetRelated()()(). The collection can be walked using the ManagementObjectCollection..::.ManagementObjectEnumerator and objects in it can be inspected or manipulated for various management tasks.
Public classManagementObjectCollection..::.ManagementObjectEnumeratorRepresents the enumerator on the collection.
Public classManagementObjectSearcherRetrieves a collection of management objects based on a specified query. This class is one of the more commonly used entry points to retrieving management information. For example, it can be used to enumerate all disk drives, network adapters, processes and many more management objects on a system, or to query for all network connections that are up, services that are paused, and so on. When instantiated, an instance of this class takes as input a WMI query represented in an ObjectQuery or its derivatives, and optionally a ManagementScope representing the WMI namespace to execute the query in. It can also take additional advanced options in an EnumerationOptions. When the Get()()() method on this object is invoked, the ManagementObjectSearcher executes the given query in the specified scope and returns a collection of management objects that match the query in a ManagementObjectCollection.
Public classManagementOperationObserverManages asynchronous operations and handles management information and events received asynchronously.
Public classManagementOptionsProvides an abstract base class for all options objects.
Public classManagementPathProvides a wrapper for parsing and building paths to WMI objects.
Public classManagementQueryProvides an abstract base class for all management query objects.
Public classManagementScopeRepresents a scope (namespace) for management operations.
Public classMethodDataContains information about a WMI method.
Public classMethodDataCollectionRepresents the set of methods available in the collection.
Public classMethodDataCollection..::.MethodDataEnumeratorRepresents the enumerator for MethodData objects in the MethodDataCollection.
Public classObjectGetOptionsSpecifies options for getting a management object.
Public classObjectPutEventArgsHolds event data for the ObjectPut event.
Public classObjectQueryRepresents a management query that returns instances or classes.
Public classObjectReadyEventArgsHolds event data for the ObjectReady event.
Public classProgressEventArgsHolds event data for the Progress event.
Public classPropertyDataRepresents information about a WMI property.
Public classPropertyDataCollectionRepresents the set of properties of a WMI object.
Public classPropertyDataCollection..::.PropertyDataEnumeratorRepresents the enumerator for PropertyData objects in the PropertyDataCollection.
Public classPutOptionsSpecifies options for committing management object changes.
Public classQualifierDataContains information about a WMI qualifier.
Public classQualifierDataCollectionRepresents a collection of QualifierData objects.
Public classQualifierDataCollection..::.QualifierDataEnumeratorRepresents the enumerator for QualifierData objects in the QualifierDataCollection.
Public classRelatedObjectQueryRepresents a WQL ASSOCIATORS OF data query. It can be used for both instances and schema queries.
Public classRelationshipQueryRepresents a WQL REFERENCES OF data query.
Public classSelectQueryRepresents a WQL SELECT data query.
Public classStoppedEventArgsHolds event data for the Stopped event.
Public classWqlEventQueryRepresents a WMI event query in WQL format.
Public classWqlObjectQueryRepresents a WMI data query in WQL format.
  DelegateDescription
Public delegateCompletedEventHandlerRepresents the method that will handle the Completed event.
Public delegateEventArrivedEventHandlerRepresents the method that will handle the EventArrived event.
Public delegateObjectPutEventHandlerRepresents the method that will handle the ObjectPut event.
Public delegateObjectReadyEventHandlerRepresents the method that will handle the ObjectReady event.
Public delegateProgressEventHandlerRepresents the method that will handle the Progress event.
Public delegateStoppedEventHandlerRepresents the method that will handle the Stopped event.
  EnumerationDescription
Public enumerationAuthenticationLevelDescribes the authentication level to be used to connect to WMI. This is used for the COM connection to WMI.
Public enumerationCimTypeDescribes the possible CIM types for properties, qualifiers, or method parameters.
Public enumerationCodeLanguageDefines the languages supported by the code generator.
Public enumerationComparisonSettingsDescribes the object comparison modes that can be used with CompareTo. Note that these values may be combined.
Public enumerationImpersonationLevelDescribes the impersonation level to be used to connect to WMI.
Public enumerationManagementStatusDescribes the enumeration of all WMI error codes that are currently defined.
Public enumerationPutTypeDescribes the possible effects of saving an object to WMI when using Put()()().
Public enumerationTextFormatDescribes the possible text formats that can be used with GetText.
Tags What's this?: wmi (x) Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
C#: Get all Information about Remote Machine      Mahiways ... Deepak Pandey   |   Edit   |   Show History
using System;
using System.Management;


namespace ConsoleApplication1{

    public class RemoteConnect{  

 public static void Main()  
 {      
  // Build an options object for the remote connection      
  // if you plan to connect to the remote      
  // computer with a different user name      
  // and password than the one you are currently using.      
  // This example uses the default values.             
  
  ConnectionOptions options = new ConnectionOptions();
  // Make a connection to a remote computer.      
  // Replace the "FullComputerName" section of the      
  // string "\\\\FullComputerName\\root\\cimv2" with      
  // the full computer name or IP address of the      
  // remote computer.      
  
  ManagementScope scope = new ManagementScope("\\\\localhost\\root\\cimv2", options);
  scope.Connect();
  //Query system for Operating System information      
  ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); 
  
  // To get information about Logical Disks on Computer
  
  SelectQuery query1 = new SelectQuery("Select * from Win32_LogicalDisk");
  
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,query);
  ManagementObjectCollection queryCollection = searcher.Get();
  
        ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope,query1);
  ManagementObjectCollection queryCollection1 = searcher1.Get();

        foreach ( ManagementObject m in queryCollection)
  {          
   // Display the remote computer information
   
   Console.WriteLine("Computer Name : {0}", m["csname"]);          
   Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
   Console.WriteLine("Operating System: {0}", m["Caption"]);
   Console.WriteLine("Version: {0}", m["Version"]);
   Console.WriteLine("Manufacturer : {0}", m["Manufacturer"]);
            Console.WriteLine();
  }
        foreach (ManagementObject mo in queryCollection1)
        {
            // Display Logical Disks information
      
            Console.WriteLine("              Disk Name : {0}", mo["Name"]);
            Console.WriteLine("              Disk Size : {0}", mo["Size"]);
            Console.WriteLine("          Disk DeviceID : {0}", mo["DeviceID"]);
            Console.WriteLine("         Disk DriveType : {0}", mo["DriveType"]);
            Console.WriteLine("         Disk MediaType : {0}", mo["MediaType"]);
            Console.WriteLine("              Disk Name : {0}", mo["Name"]);
            Console.WriteLine("       Disk PNPDeviceID : {0}", mo["PNPDeviceID"]);
            Console.WriteLine("      Disk ProviderName : {0}", mo["ProviderName"]);
            Console.WriteLine("        Disk VolumeName : {0}", mo["VolumeName"]);
            Console.WriteLine("        Disk SystemName : {0}", mo["SystemName"]);
            Console.WriteLine("Disk VolumeSerialNumber : {0}", mo["VolumeSerialNumber"]);
            Console.WriteLine();
        }
        
        string line;
        line = Console.ReadLine(); 
    }
  }
}

 
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker