I've got a block of C++ code in which I'm trying to call a company-specified WMI method. While attempting to build the IWbemClassObject representing the parameters, I get a WBEM_E_NOT_FOUND error message. According to the MSDN site, this should not be a valid 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;
}
Does anyone know why this might be happening, and how I can fix it?
Many thanks in advance, Zach
Typically this error comes up with "GET" commands. In most cases the particular cause of the error depends on the WMI class you're attempting to access. For example, WMIDiag has this to say regarding when this error is returned when attempting to connect to a performance counter:
In other cases, this error appears to be most commonly caused by a corrupted repository. See this MS KB article for an example.
Since you mentioned a "Company specified" WMI method, I'm assuming that you've registered your own WMI provider. I would suspect that this provider is not properly registered with WMI before I go rebuilding the repository.
It's been almost a year since you asked the question, I guess you probably figured it out. If so, I think the community would appreciate you posting your results here so that other users can benefit from it.