A Simple Guide to WMI Provider

Environment: VC.NET, XP, C#

Table of Contents

Introduction
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
Conclusion
Appendix A: Definitions & Acronyms
Appendix B:WMI Tools
Appendix C: Important Reading
Appendix D: Developing Steps to Support SNMP

Introduction

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).



Click here for a larger image.

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.



Click here for a larger image.

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. Click here for a larger image.

  11. Subscribe for events: 'Add Event Query 'to the 'Management Events' item.
  12. Check the 'Custom' Events type.
  13. Add the Landing and Jump events (situated under the parachute_company namespace).
  14. Start and stop the service. The MSDEV output window will display the events data.


  15. Click here for a larger image.

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.)

Conclusion

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

Books:

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

Articles:

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.

Downloads

Download demo project - 25 Kb
Download demo executable - 6 Kb


Comments

  • opauoivdntoaliziejtxmeiytkt

    Posted by Kaporpignorma on 07/11/2013 07:05pm

    dbp 锘? lbn 锘? bsm 锘?

    Reply
  • gdfgwe

    Posted by viagra on 07/05/2013 07:20pm

    viagra 50 mg generique commander viagra viagra acquistare viagra roma

    Reply
  • sdfqasfa

    Posted by comprare cialis on 06/23/2013 01:00am

    [url=http://pizza-maestro.com/]cialis generique[/url] cialis [url=http://studiolepre.com/]cialis[/url] acquisto cialis

    Reply
  • cheap clarisonic can renovate your incrustation

    Posted by iouwanzi on 06/06/2013 10:47am

    [url=http://www.miaclarisonicaustralia.org/]clarisonic mia australia[/url] et en plus vous savez quoi ? Cette approche n’est pas presque tous. Est normalement photographié, à peu près chaque période unique, juste par le photographe professionnel populaire particulière ? Certes, le logiciel n’est pas tout un plus petit montant connu Katy.concernant pour lequel vous consacrez une bonne période de 7 jours. Juste pour une partie, Document mis au point plusieurs évolutions dont je parle avant longtemps. Bien sûr, le logiciel peut-être promi ! Toujours juste avant tout cela, Document allait donner à ma propre volonté. [url=http://www.australiaclarisonic.com/]clarisonic brush[/url] Excessive, que le logiciel est généralement toute expression caractérisant cette campagne innovante spécifique dénommée collection écarlate dans hommage vers les années folles. Juste pour votre affaire, la présence publique dans le type, Katy Perry est immortalisée tout simplement parce que le blanc lumineux au sol avec la fonction habilité par le numérique photographe David LaChapelle. Golf sautes très étonnante et encore plein d’identité parfaite pour la commercialisation des cas uniques ghd. [url=http://www.australiaclarisonic.com/]clarisonic brush[/url] Avec concernant la saison de Noël, j’ai couru à travers une idée de cadeau vraiment attractif, votre package de Collection de nuit. un nouvel ensemble de boîte très exquis option limitée en place qui comprend également tous les flambant neuf G Platinum intemporelle GHD Styler haute définition, matériel résistant à la chaleur, seulement deux caractéristiques montre les cheveux bouclés, un nouveau miroir de belle main baroque, un séchoir de cheveux bouclés nouvelles d’acquérir voyage autour ultra-compact, ainsi qu’une belle organisation.

    Reply
  • sdqwwdsadf

    Posted by cialis on 05/07/2013 08:02pm

    prix cialis cialis acheter belgique cialis cialis farmaco per impotenza venta cialis comprar cialis madrid cialis acquisto cialis

    Reply
  • asdqasdqwwe

    Posted by cialis on 05/06/2013 04:51pm

    vente cialis prix cialis en pharmacie generico cialis comprare cialis comprar cialis cialis vademecum cialis online cialis dove comprare

    Reply
  • asdqwe

    Posted by cialis on 05/05/2013 03:04pm

    cialis generique cialis generique cialis cialis ricetta medica cialis cialis espana comprare cialis costo cialis farmacia

    Reply
  • sdczxceasd

    Posted by cialis on 04/17/2013 03:45pm

    cialis prix cialis acheter cialis commander cialis acquisto cialis cialis italia precio cialis comprar cialis online

    Reply
  • asdasdqwsqwe

    Posted by viagra on 04/08/2013 01:06am

    acheter viagra achat viagra achat viagra viagra bayer en ligne viagra sin receta venta viagra espana viagra tadalafil comprare

    Reply
  • fadqw

    Posted by viagra on 04/05/2013 04:47pm

    viagra generique viagra generique viagra viagra vente viagra generico comprar viagra farmacia viagra acquisto acquisto viagra

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Event Date: April 15, 2014 The ability to effectively set sales goals, assign quotas and territories, bring new people on board and quickly make adjustments to the sales force is often crucial to success--and to the field experience! But for sales operations leaders, managing the administrative processes, systems, data and various departments to get it all right can often be difficult, inefficient and manually intensive. Register for this webinar and learn how you can: Align sales goals, quotas and …

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds