首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回WBEM_E_NOT_FOUND错误的IWbemClassObject->Put方法

返回WBEM_E_NOT_FOUND错误的IWbemClassObject->Put方法
EN

Stack Overflow用户
提问于 2013-01-14 19:50:50
回答 1查看 937关注 0票数 0

我有一个C++代码块,在其中我试图调用一个公司指定的WMI方法。在试图构建表示参数的IWbemClassObject时,我会得到一条WBEM_E_NOT_FOUND错误消息。根据MSDN站点,这不应该是一个有效的HRESULT。

代码语言:javascript
复制
/* pSvc has been setup already, all calls returned S_OK. Ugly Debugging statements have been sprinkled throughout the code. */
HRESULT hres;
IWbemClassObject* DataInClass;
IWbemClassObject* DataOutClass;
IWbemClassObject* CallingObject;
/* Grab the types of parameters we will be using for Input and Output.
DataIn and DataOut are set to the classes we will  be using */
hres = pSvc->GetObject(
    _bstr_t("ObjectName"),
    WBEM_FLAG_RETURN_WBEM_COMPLETE,
    NULL,
    &CallingObject,
    NULL
    );
cout << "GetObject:" << hres << endl;

string function_type = "MethodName";

hres = CallingObject->GetMethod(
    _bstr_t(function_type.c_str()),
    0,
    &DataInClass,
    &DataOutClass
    );
cout << "GetMethod:" << hres << endl;
if(hres == WBEM_S_NO_ERROR) cout << "No Error" << endl;
if(hres == WBEM_E_NOT_FOUND) cout << "Not found" << endl;
if(hres == WBEM_E_OUT_OF_MEMORY) cout << "OOM" << endl;
/* Create an instance of DataIn and DataOut and populate the parameters */
IWbemClassObject* DataIn;
IWbemClassObject* DataOut;
hres = DataInClass->SpawnInstance(0, &DataIn);
hres = DataOutClass->SpawnInstance(0, &DataOut);

/* NOTE: up to this point, all HRESULTS have been returning S_OK. I'm getting appropriate pointer values, so it appears that the code can connect to WMI. */

/* Set all of the parameters needed for DataIn */
VARIANT var;
// Active: true
_variant_t varActive(true);
var = varActive.Detach();
hres = DataIn->Put(_bstr_t("Active"), 0, &var, 0);
VariantClear(&var);
switch(hres){
case WBEM_E_FAILED: cout << "Failed" << endl; break;
case WBEM_E_INVALID_PARAMETER: cout << "ip" << endl; break;
case WBEM_E_INVALID_PROPERTY_TYPE: cout << "ipt" << endl; break;
case WBEM_E_OUT_OF_MEMORY: cout << "oom" << endl; break;
case WBEM_E_TYPE_MISMATCH: cout << "typem" << endl; break;
case WBEM_S_NO_ERROR: cout << "ok" << endl; break;
case WBEM_E_NOT_FOUND: cout << "WHAT!?" << endl; break; // This is the error code being returned from DataIn->Put
default: cout << "nota?" << endl; break;
}

有人知道为什么会发生这种事吗?我怎么才能解决呢?

先谢谢你,扎克

EN

回答 1

Stack Overflow用户

发布于 2013-12-09 17:44:13

通常,这个错误会产生"GET“命令。在大多数情况下,错误的特殊原因取决于您试图访问的WMI类。例如,对于试图连接到性能计数器时何时返回此错误,WMIDiag有如下说明:

当WMI性能类丢失时(即'Win32_PerfRawData_TermService_TerminalServices'),通常是因为WMI类提供程序缺乏缓冲区刷新,公开WMI性能counters.You可以使用以下命令刷新WMI类提供程序缓冲区:‘WINMGMT.EXE /SYNCPERF’

在其他情况下,此错误似乎最常见是由损坏的存储库引起的。有关示例,请参阅 MS KB文章。

由于您提到了“公司指定的”WMI方法,我假设您已经注册了自己的WMI提供程序。在我重新构建存储库之前,我会怀疑这个提供程序没有在WMI中正确注册。

你问这个问题已经快一年了,我想你大概想明白了。如果是这样的话,我想社区会很感激你在这里发布你的结果,这样其他用户就可以从中受益。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14325567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档