Developing a WMI Provider

A provider is a Component Object Model (COM) object that acts as an intermediary between WMI and a managed object. For example, when an application or script requests disk data using the WMI Win32_LogicalDisk class, the data is obtained dynamically through the preinstalled Win32 provider.

If you want to supply data through WMI to other applications, you can create an unmanaged code provider by writing a COM server or through the WMI ATL wizards in Visual Studio. You can write a managed code provider by using WMI in the .NET Framework. The topics in this section describe the process of writing an unmanaged COM provider.

Note

To ensure that all of your WMI class definitions for managed objects are restored to the WMI repository if WMI has a failure and restarts, use the #pragma autorecover preprocessor instruction in your Managed Object Format (MOF) file.

A provider consists of classes defined in the Managed Object Format (MOF) schema and a DLL file which carries out the functions of the provider. For example, the MOF that defines the classes of the Win32 provider is CIMWin32.mof and the DLL is CIMWin32.dll, both are found in %windir%\System32\Wbem.

The MOF schema for the provider may contain several provider types. For example, the Event Log Provider has instance, method, and event provider types in one MOF file named Ntevt.mof. It is recommended that all of the classes and registration schema for related providers be assembled in one file, rather than creating one file per class.

In addition to using preinstalled providers, you can create your own provider to supply information about a hardware device or the operations of software.

The following table lists the basic tasks that create a provider.

Task Description
Designing Managed Object Format (MOF) Classes Develop a model for the entities you want to manage through WMI and create a Managed Object Format (MOF) file to describe the schema.
Supplying Data to WMI by Writing a Provider Create the most basic provider that is coupled to WMI.
Incorporating a Provider in an Application Include the provider as a component within an application if it does not run all of the time.
Registering a Provider Register the provider with COM and WMI.
Initializing a Provider Implement the IWbemProviderInit and IWbemProviderInitSink interfaces.
Making Calls to WMI Call WMI interfaces from a provider.
Impersonating a Client Set security to access a client application.
Updating a Provider Improve the provider as needed.
Unloading a Provider Remove the provider from memory during shutdown or when the provider is idle.
Debugging Providers and Provider Configuration and Troubleshooting Classes Debug your provider using facilities supplied by WMI.
Getting and Providing Data on a 64-bit Computer Evaluate whether you need a 32-bit application compatibility provider or if the 64-bit provider can supply data to both clients.

The following topics discuss the steps needed to write different types of providers: