Windows Management Instrumentation SDK Sample


Decoupled Event Provider

The Decoupled event provider sample code creates an event provider for WMI.  An event provider allows event instances to be forwarded based on some change in state of a dynamic data source. The event provider is called when a client request requires information relevant to that particular provider. The event provider is a decoupled provider. A decoupled provider 'decouples' the lifetime of the hosting process from the liftetime of the wmi service, this is distinct from existing 'coupled' providers that are launched by the WMI service through the com activation mechanism. Typically an application or server process is launched and services requests relating to a particular application domain, e.g. database server, mail server, etc. A decoupled provider registers it's ability to handle provider requests, associated with the application domain, during the startup procedure for the application or service; whilst the application or service is not running or registered WMI will not attempt to satisfy client requests associated with the provider.

 

The sample provider supports a single event class 'SampleEvent ', that forwards a simple event instance.

 

Building the Provider EXE

 

The EXE can be built using Microsoft Visual C++. 

 

1.      Select File + Open Workspace

2.      Select the SdkSample.DSP file

 

 

Registering the event Class and provider

 

 

You must also compile the MOF in order to make the WMI CIMOM aware of the class.  From the command line in the sample installation directory, type the following:

MOFCOMP ProvReg.MOF 

At this point, you can run the executable sdksample.exe in combination with the event consumer sample and here a beep as each event is received by the consumer.

 

General Notes

 

Things to remember when you're building your own WMI provider:

 

1.        WMI interfaces are defined in wbemcli.h and wbemprov.h found in the wmi\include directory.  You may #include both these files by including just wbemidl.h located in the same directory.

 

2.        WMI interface CLSIDs are defined in wbemuuid.lib. If you get unresolved externals in interfaces and CLSIDs, this is what is missing.

 

3.        You'll need to link with oleaut32.lib and ole32.lib to get the needed COM support.

 

4.        In the Link|Output settings, specify 'wWinMainCRTStartup' as the entry point. This is per the Unicode programming instructions.

 

5.        If you're using the makefiles, don't forget to set the Visual C++ environment variables. This is done by running VCVARS32.BAT.