Creating WMI Clients
WMI provides a standardized system management infrastructure that can be leveraged by a number of different clients. These clients range from the wmic.exe command line tool to System Center Operations Manager. You can write your own WMI clients by using either the WMI Scripting API, the native C++ API or by using the types in the System.Management .NET Framework class library namespace.
How to create a WMI client
The core functionality of WMI consists of retrieving objects from the WMI repository and examining the properties of those objects. You can also choose to update those properties, or call methods on those properties. The following examples show how to perform a basic WMI administration task: retrieving the name of the local computer.
|Creating a client with PowerShell
||WMI and PowerShell are tightly integrated; as such, retrieving WMI objects with PowerShell is simply a matter of calling the Get-WmiObject cmdlet. Note that for consistency, the first code snippet explicitly states many of the default values; the second assumes that the default values are correct.
Creating a client with VBScript
VBScript was the original scripting language that had common use with WMI. While PowerShell has become more popular, many of the existing code samples in this documentation are written in VBScript. Note that this particular VBScript sample explicitly states both the local machine path as well as the impersonation level; this is not required, but is often a best practice.
Creating a client with C# ([Microsoft.Management.Infrastructure](https://msdn.microsoft.com/library/microsoft.management.infrastructure.aspx))
This namespace contains the current solution for accessing WMI with managed code, and is known as the Windows Management Infrastructure (MI, or WMIv2). Currently, MI is the supported technology for creating managed management clients. For more information, see [How to Implement a Managed MI Client](https://msdn.microsoft.com/library/dn313202) and [How to Implement a Native MI Client](https://msdn.microsoft.com/library/dn314432).
Creating a client with C# ([System.Management](https://msdn.microsoft.com/library/system.management.aspx))
This namespace contains the original solution for accessing WMI with managed code. While the [System.Management](https://msdn.microsoft.com/library/system.management.aspx) classes are still available, the [Microsoft.Management.Infrastructure](https://msdn.microsoft.com/library/microsoft.management.infrastructure.aspx) classes are generally more efficient and scale better. As such, it is recommended that you use the MI classes, rather than the original WMI classes.
The following table lists the topics covered in this section.
|Connecting to WMI on a Remote Computer||Describes a number of issues that arise when clients use the WMI infrastructure on a remote computer.|
|WMI Tasks for Scripts and Applications||Shows example WMI client code.|
|Creating a WMI Application or Script||Provides information about creating various WMI clients.|
|Monitoring Performance Data||Describes how to use WMI to monitor performance data.|
|Receiving a WMI Event||Describes how to view WMI events.|
|Monitoring Events||Describes how to monitor WMI events.|
|Querying with WQL||Introduces the WMI Query Language (WQL).|
|Querying the Status of Optional Features||In Windows 7, WMI implemented the Win32_OptionalFeature class. This class retrieves the status of the optional features that are present on a computer.|
|Describing the Location of a WMI Object||Focuses on the syntax for describing the location of a WMI managed entity.|
|Accessing Other Operating System Features with WMI||Describes how to write WMI clients that access device drivers, Active Directory, and SNMP devices.|
|Accessing Data in the Interop Namespace||Association providers enable Windows Management Instrumentation (WMI) clients to traverse and retrieve profiles and associated class instances from different namespaces.|
|Manipulating Class and Instance Information||Describes the common tasks that WMI clients must perform.|
|Linking Classes Together||Discusses the view provider and how it can be used to bring together information from multiple WMI classes.|
|Modifying the System Registry||Describes how WMI clients can use WMI to manage system registry information.|