Professional Documents
Culture Documents
Windows Management Instrumentation (WMI) : Lecture (20 Jan)
Windows Management Instrumentation (WMI) : Lecture (20 Jan)
Windows Management Instrumentation (WMI) : Lecture (20 Jan)
ManagementScope scope = new ManagementScope( "\\\\osman\\root\\cimv2", options); scope.Connect(); //Query system for Operating System information ObjectQuery query = new ObjectQuery( "SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCollection = searcher.Get(); foreach (ManagementObject m in queryCollection) { // Display the remote computer information Console.WriteLine("Computer Name : {0}", m["csname"]);
Osman Khalid, Lecturer, Computer Sciences Department, COMSATS Institute of Information Technology
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"]); } } }
Connect
ManagementObjectSearcher Class Retrieves 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.
Osman Khalid, Lecturer, Computer Sciences Department, COMSATS Institute of Information Technology
ManagementObjectCollection Class Represents 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
EXAMPLES
select Name FROM Win32_ComputerSystem select Caption, Description, DeviceID, NumberOfFunctionKeys, Status from win32_keyboard select Caption, Manufacturer, Status from Win32_FloppyDrive