Bewerken

Delen via


Creating a WMI Application Using C++

To create an application for WMI using C++: you must initialize COM, access and set WMI protocols, and perform a manual cleanup. However, C++ does have the advantage of flexibility and power. Therefore, while you are better served in using Visual Basic Scripting Edition (VBScript) or Windows PowerShell for simple processes, C++ works better for more sophisticated applications and is required for writing providers.

The following procedure describes how to create a WMI application.

To create a WMI application

  1. Initialize COM.

    Because WMI is based on COM technology, you must perform calls to the CoInitializeEx and CoInitializeSecurity functions to access WMI.

  2. Create a connection to a WMI namespace.

    By definition, WMI runs in a different process than your application. Therefore, you must create a connection between your application and WMI.

  3. Set the security levels on the WMI connection.

    To use the connection you create to WMI, you must set the impersonation and authentication levels for your application.

  4. Implement the purpose of your application.

    WMI exposes a variety of COM interfaces use to access and manipulate data across your enterprise. For more information, see Manipulating Class and Instance Information, Receiving a WMI Event, and COM API for WMI.

    This is where the bulk of your WMI client application should exist, such as accessing WMI objects or manipulating data.

  5. Cleanup and shut down your application.

    After you complete your queries to WMI, you should destroy all COM pointers and shut down your application correctly.

For more information and a code example about how to create a WMI application, see Example: Creating a WMI Application.