【发布时间】:2016-05-12 14:03:12
【问题描述】:
我找到了一些用于 WMI 实例删除的 C# 和 VBS 示例,但是我需要使用 C++ 实现。
我的示例代码:
CoInitialize(NULL);
HRESULT hRes;
//Obtain the initial locator to WMI
CComPtr<IWbemLocator> pLoc = NULL;
hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*) &pLoc);
if(FAILED(hRes))
return 1;
//Connect to WMI through the IWbemLocator::ConnectServer method
CComPtr<IWbemServices> pSvc = NULL;
//Connect to the root namespace with the current user and obtain pointer pSvc to make IWbemServices calls.
hRes = pLoc->ConnectServer(L"ROOT\\SUBSCRIPTION", NULL, NULL, 0, NULL, 0, 0, &pSvc);
if(FAILED(hRes))
return 1;
hRes = pSvc->DeleteInstance(
L"CommandLineEventConsumer.Name='{709782F3-E860-488E-BD8A-89FBC8C1495C}'",
WBEM_FLAG_RETURN_IMMEDIATELY, NULL, NULL);
return 0;
根据我找到的here 和here,我的代码应该可以工作。我肯定有CommandLineEventConsumer 命名为{709782F3-E860-488E-BD8A-89FBC8C1495C}
我的代码在IWbemServices::DeleteInstance 上失败,错误代码0x80041008(调用的参数之一不正确)。
如果有人在我的代码中发现错误,我将不胜感激。或者可能需要一些特权才能做到这一点?
【问题讨论】:
标签: c++ windows winapi com wmi