A Simple Guide to WMI Provider

Environment: VC.NET, XP, C#

Table of Contents

What Is Platform Management?
What Is WMI?
What Is WMI Provider?
Developing WMI Provider—Where to Start?
Defining Namespace
Sample Project
How to Use the Demo Project
Known Problems in the .NET WMI Implementation
Appendix A: Definitions & Acronyms
Appendix B:WMI Tools
Appendix C: Important Reading
Appendix D: Developing Steps to Support SNMP


This article’s purpose is to describe how to develop a WMI provider in the .NET framework. There are several incentives for writing this article:

  • The lack of simple examples for writing a WMI provider in C#.
  • Many developers are not familiar with WMI and therefore don’t make use of this powerful technology.
  • By now there are too many Management buzz words that requires simple explanations.

This article does not include the use of SNMP and does not answer the following questions:

  • How to write MIB?
  • How to configure the Windows SNMP service?
  • How to subscribe for traps?

Nevertheless, anyone who’s interested in those questions can find some useful notes regarding the required steps to expose managed application to SNMP (see Appendix D).

Management includes a ‘Managed object,’ ‘Managed object provider,’ and a ‘Management consumer.’ A Managed object can be a hardware device, driver, or a software application that we would like to configure and to receive events from. The management consumer is the client application that wants to receive those events, and the managed object provider is the mediator that provides this interaction between the two. The Windows Management Instrumentation (WMI) supplies the standards means to do this.

What Is Platform Management?

In a nutshell, Platform Management is the means to manage and monitor the health of a system. This may fall into the following categories:

  • Configuration—initialization and settings of various aspects of the platform objects such as timeout values, user count thresholds, database connection strings, and so forth.
  • Performance measurements—measure end to end process in regards to duration, optimization, and so on.
  • Hearth beats monitoring—manage component life time. Start and stop services, receiving components state, and the like.
  • Information exposing—expose platform information that might be valuable for system administrators, billing, and so forth.
  • Alerts mechanism—informative events, errors, and critical errors that happens in the platform.
  • Corrective events mechanism—As opposed to post mortem events, this kind of events gives to the administrators the ability to perform actions to prevent upcoming errors.

What Is WMI?

WMI stands for Windows Management Instrumentation. This is the Microsoft implementation to two industry standards of DMTF (Desktop Management Task Force). The first is CIM (Common Information Model) and the second is WBEM (Web-Based Enterprise Management).

The WMI core is already a part of Windows ME/2000 and XP. The WMI enables the management capabilities by supplying the standard storage component (CIM), the means to set and get information to and from the storage, and the ability to dock third-party providers (same as plug-ins) to the Providers Manager (CIMOM). This industry standard compliancy allows alien components to share management environment locally and remotely by using SNMP.

What Is WMI Provider?

WMI Provider is a software component that functions as a mediator between the CIM Object Manager and managed objects. By using the WMI APIs, providers supply the CIM Object Manager with data from managed objects, handle requests on behalf of management applications, and generate event notifications.

Developing WMI Provider—Where to Start?

To expose a software component such as a service through the WMI, one needs to write a WMI provider. This plug-in (provider) exposes the service to the WMI and provides the interface to receive information and to interact with the service. Until recently, a WMI Provider was written as a COM component and now, with the emerging of the .NET framework, it is easier to develop providers.

In case you aren’t familiar with the MOF syntax, you can simply start with developing the WMI Provider (see the sample section). When it’s all done and finished, use the InstallUtil.exe (see Appendix B) tool to enter the managed class into the CIM schema; then, if you want, you can generate the MOF file from the WMI CIM Studio (it is highly recommended because it is the best way to learn this syntax).

If you do know how to write MOF file (lucky guy), then use the Mgmtclassgen utility (see Appendix B) to create the C# classes and events for the WMI provider.

Defining Namespace

Namespace enables you to logically gather related managed objects under one logic umbrella. It is recommended to define your own namespace for several reasons:

  • Order
  • Efficiency—Namespace like ‘CIMV2’ and ‘Default’ contains a lot of Managed objects. Defining a unique namespace enables you to save time while looking for your objects.

Sample Project

The demo includes a simple .NET service (‘Parachute service’—Managed application ) and a WMI provider (‘Parachute provider’). For simplicity reasons, the sample uses the MSDEV IDE extension for VS.NET Server Explorer (see Appendix B) as the consumer application.

The Service code is quite simple. Add a reference to the ParachuteProvider and to System.Managment assemblies. In the ExposeMeToWMI method, we instantiate the provider, set some values, and then publish (Instrumentation.Publish()) the provider to the WMI. The publish call registers the provider and the managed object is mapped into the CIM schema. Events are fired when the service starts and stops.

Note: The provider instance is valid only when the service is started.

The Provider code contains the following actions:

  • Adds a reference to the System.Management assembly.
  • Defines the instrumented namespace parachute_company under root: [assembly:Instrumented(“root/parachute_company”)]

Note: The managed object schema will be defined under this namespace.

Add an instance installer in case we want to publish the provider directly via the InstallUtil tool. In this example, we publish the provider through the service.

Defines events by using the InstrumentationType.Event attribute: [InstrumentationClass(InstrumentationType.Event)]. Defines WMI Provider instance using the InstrumentationType.Instance attribute:[InstrumentationClass(InstrumentationType.Instance)]

Note: The provider code can be just as well written in the service.

How to Use the Demo Project

  1. Register the Parachute service to the SCM (Service Control Manager) with the InstallUtil tool (%systemroot%%\Microsoft.NET\Framework\<framework version&t;\InstallUtil.exe).

    InstallUtil.exe <service file>.

  2. Open the SCM \Administrative tools\ Services.
  3. Log on as ‘This account’—Right-click on the service name (Parachute) -> Properties -> Log on tab -> check the ‘This account’ enter user name and password (the user must be under Administrator group).
  4. Start the service.
  5. Install the MSDEV IDE Management extension for VS.NET Server Explorer.
  6. Open the MSDEV in ‘Server Explorer’ view.
  7. Add your computer to the explorer: Right-click on the Servers root tree ->Add Server.
  8. Add Management class to the ‘Management Classes’ item. Look for the Parachute class under to the parachute_company namespace.
  9. Expand the Parachute item and you should see the brand new instance. Take a look at the instance properties; you can see that the parachute color is exposed (red) by WMI.
  10. Subscribe for events: ‘Add Event Query ‘to the ‘Management Events’ item.
  11. Check the ‘Custom’ Events type.
  12. Add the Landing and Jump events (situated under the parachute_company namespace).
  13. Start and stop the service. The MSDEV output window will display the events data.

Known Problems in the .NET WMI Implementation

.NET framework, currently, does not support methods and properties settings.

For some reason, the WMI Event Registration tool to subscribe an events does not work. You can use instead the MSDEV IDE: http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=ef7594d3-4907-4af6-b7d8-6e22115ffaf0.

The schema is not removed when Installutil.exe /u is run. (You can remove it by using wbemtest.exe.)


Well, that’s it, folks. Hopefully, this article will stimulate you to drill down into the WMI technology and to take advantage of it. Please send feedback, bug reports, or suggestions here.

Appendix A: Definitions & Acronyms

  • CIMÿCommon Information Model—this is the premier concept of WBEM by this model WMI stores the Managed objects data (namespace, classes, methods, properties, and so forth).
  • CIM Repository—This is the storage that holds the Managed objects data. The structure of the CIM repository is built upon the DMTF.
  • CIMOM—Common Information Model object manager. The CIM repository is managed by the CIMOM, which acts as an agent for object requests. The CIMOM tracks available classes and determines which provider is responsible for supplying instances of these classes.
  • DMTF—Distributed Management Task Force—The DMTF consortium was founded in May of 1992. This initiative was conceived and created by eight companies such as: BMC Software Inc., Cisco Systems Inc., Compaq Computer Corp., Intel Corp., Microsoft Corp. and so on. The aims of this consortium are to define industry standards for management.
  • MIB—Management Information Base describes a set of managed objects. Each managed object in a MIB has a unique identifier.
  • MOF—Managed Object Format. This text file includes the class definition of on or more managed object. You can export and import this definition from the CIM repository by using the WMI CIM Studio.
  • Schema—a group of classes that describe a particular management environment.
  • SNMP—Simple Network Management Protocol. SNMP is an Internet standard defined by the IETF and is a part of TCP/IP suite of protocols. SNMP is the protocol by which managed information is travel between stations and agents. Management information refers to a collection of managed objects that reside in a virtual information store called a Management Information Base (MIB).
  • WBEM—Web-Based Enterprise Management—WBEM stands for several DMTF industry standards including the Common Information Model. WBEM provides a standardized way to access information from various hardware and software management systems in an enterprise environment.

Appendix B: WMI Tools

Appendix C: Important Reading


Developing WMI Solution, http://www.wbem.co.uk/. Chapter 8, “Developing .NET Management Application.”


Appendix D: Developing Steps to Support SNMP

  1. Obtain an OID (Object IDentifier) from IANA. To participate in the SNMP arena, you need to define your classes and events in a MIB file. First, The SNMP root node must be a unique number (only ONE MIB/SNMP Private Enterprise number is permitted per organization). IANA: http://www.iana.org/cgi-bin/enterprise.pl
  2. Create a MIB (Management Information Base) file (check out Appendix B for some useful and easy-to-use MIB editors). Define classes and SNMP traps (events) that eventually will be exposed by the WMI Provider.
  3. Compile the MIB file using the SMI2SMIR utility. This will generate a MOF file.
  4. Compile the MOF file using the mofcomp.exe compiler to check the MOF file syntax correctness.
  5. Create the C# classes and events with the Mgmtclassgen utility (refer to Appendix B). Use the C# classes to create WMI provider.


Download demo project – 25 Kb

Download demo executable – 6 Kb

More by Author

Must Read