When creating an application that is to be instrumented, the best practice is to include the provider as a component within the application itself. This practice permits Windows Management Instrumentation (WMI) to interact with the service provider directly instead of indirectly through the program API. Decoupling the provider from WMI also puts the application in control of the provider lifespan, instead of WMI. For more information about writing a provider that runs in the WMI process, see Supplying Data to WMI by Writing a Provider. For more information about hosting model and security settings for the provider, see Provider Hosting and Security.
The following diagram illustrates the relationship between WMI, a decoupled provider, and an application.
The decoupled provider supports instance, method, event providers, and event consumers. It does not support class and property providers. For more information, see Writing a Class Provider and Writing a Property Provider.
The code examples in this topic require the following references and #include statements to compile correctly.
The following procedure uses C++ code examples to describe how to incorporate a decoupled provider in your application. The initialization method of the application performs the following steps so that WMI only interacts with a registered decoupled provider.
To implement a decoupled provider in a C++ application
Initialize the COM library for use by the calling thread.
The following code example shows how to initialize the COM library.
This level establishes the security level required of other processes to access the client process' information. The authentication level should be RPC_C_AUTHN_LEVEL_DEFAULT. For more information, see Maintaining WMI Security.
The following code example shows how to set the default security level.
Just prior to terminating, the application must clean up after itself. The following procedure describes how to unregister the decoupled provider so that WMI does not attempt to query it for information.
The following procedure describes how to unregister the decoupled provider.
To unregister the decoupled provider
Unregister and release the registrar.
The following code example shows how to unregister and release the registrar.
This learning path covers Windows Management Instrumentation (WMI) and Common Information Model (CIM). These technologies help to access information about a computer. Additionally, both technologies provide local and remote access to management information from the operating system, computer hardware, and installed software.