Unhandled exception at 0x00a11e5e in muj.exe: 0xC0000005: Access violation reading location 0x00000000.
Problem with the above specified runtime error.
Please help me out.
Here is the code which generates such an exception
BSTR MethodName = SysAllocString(L"Create");
BSTR ClassName = SysAllocString(L"Win32_Process");
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
IWbemClassObject* pInParamsDefinition = NULL;
hres = pClass->GetMethod(MethodName, 0,
&pInParamsDefinition, NULL);
IWbemClassObject* pClassInstance = NULL;
hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);
VARIANT varComman;
varComman.vt = VT_BSTR;
varComman.bstrVal = L"CScript E:/vinay.vbs";
VARIANT varCommand;
varCommand.vt = VT_BSTR;
varCommand.bstrVal = L"CScript E:/mof.vbs";
hres = pClassInstance->Put(L"CommandLine", 0,
&varComman, 0);
wprintf(L"The command is: %s\n", V_BSTR(&varComman));
hres = pClassInstance->Put(L"CommandLine", 0,
&varCommand, 0);
wprintf(L"The command is: %s\n", V_BSTR(&varCommand));
IWbemClassObject* pOutParam = NULL;
hres = pSvc->ExecMethod(ClassName, MethodName, 0,
NULL, pClassInstance, &pOutParam, NULL);
IWbemClassObject* pOutParams = NULL;
if (FAILED(hres))
{
cout << "Could not execute method. Error code = 0x"
<< hex << hres << endl;
VariantClear(&varCommand);
SysFreeString(ClassName);
SysFreeString(MethodName);
pClass->Release();
pInParamsDefinition->Release();
pOutParams->Release();
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1;
}
VARIANT varReturnValue;
hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0,
&varReturnValue, NULL, 0);