gpt4 book ai didi

c++ - IWbemClassObject->Put 方法返回 WBEM_E_NOT_FOUND 错误

转载 作者:行者123 更新时间:2023-11-28 07:48:38 26 4
gpt4 key购买 nike

我有一段 C++ 代码,我在其中尝试调用公司指定的 WMI 方法。在尝试构建表示参数的 IWbemClassObject 时,我收到 WBEM_E_NOT_FOUND 错误消息。根据MSDN site ,这不应该是有效的 HRESULT。

/* 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;
}

有谁知道为什么会发生这种情况,我该如何解决?

非常感谢,扎克

最佳答案

通常此错误会出现在“GET”命令中。在大多数情况下,错误的具体原因取决于您尝试访问的 WMI 类。例如,WMIDiag关于尝试连接到性能计数器时何时返回此错误,有这样的说法:

When a WMI performance class is missing (i.e. 'Win32_PerfRawData_TermService_TerminalServices'), it is generally due to a lack of buffer refresh of the WMI class provider exposing the WMI performance counters.
You can refresh the WMI class provider buffer with the following command:
'WINMGMT.EXE /SYNCPERF'

在其他情况下,此错误似乎最常见的原因是存储库损坏。参见 this MS 知识库文章的示例。

既然您提到了“公司指定的”WMI 方法,我假设您已经注册了自己的 WMI 提供程序。在我重建存储库之前,我怀疑此提供程序未正确注册到 WMI。

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

关于c++ - IWbemClassObject->Put 方法返回 WBEM_E_NOT_FOUND 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14325567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com