勇芳软件工作室.汉化:  Windows Management Instrumentation > Creating WMI Clients > Creating a WMI Application or Script > Creating a WMI Application Using C++ >

Cleaning up and Shutting Down a WMI Application

Previous pageReturn to chapter overviewNext page

为您的IWbemServices指针设置安全级别后,您可以访问WMI的各种功能。使用WMI后,您必须关闭应用程序。

 

以下过程介绍如何清理和关闭WMI应用程序。

 

清理并关闭WMI应用程序

 

1.释放所有打开的COM接口。

 

您必须记住要发布的两个主要界面是IWbemServicesIWbemLocator.

 

2.致电CoUninitialize.

 

与所有COM应用程序一样,您必须在应用程序结束时调用CoUninitialize.

 

3.退出您的申请

 

以下代码示例显示如何退出WMI客户端应用程序。

 

// The following #include and #define statements need

// to be used with this code:

// #define _WIN32_DCOM

// #include <wbemidl.h>

// # pragma comment(lib, "wbemuuid.lib")

 

// pSvc was declared as IWbemServices *pSvc;

// pLoc was declared as IWbemLocator *pLoc;

 

pSvc->Release();

pLoc->Release();    

CoUninitialize();

return 0;   // Program successfully completed.

 

注意 PSVC变量的类型为IWbemServices*PLOC变量的类型为IWbemLocator*.

 

您现在已经成功初始化了COM,访问了WMI,并退出了您的应用程序。有关详细信息,请参阅示例:创建WMI应用程序.