本文介绍了Windows Cosole应用程序,WMI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
muj.exe中0x00a11e5e处未处理的异常:0xC0000005:访问冲突读取位置0x00000000.
上面指定的运行时错误出现问题.
请帮帮我.
这是生成此类异常的代码
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);
// Create the values for the in parameters
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";
// Store the value for the in parameters
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;
//hres = pSvc->ExecMethod(ClassName, MethodName, 0,
//NULL, pClassInstance, &pOutParams, NULL);
// Execute Method
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; // Program has failed.
}
// To see what the method returned,
// use the following code. The return value will
// be in &varReturnValue
VARIANT varReturnValue;
hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0,
&varReturnValue, NULL, 0);
推荐答案
这篇关于Windows Cosole应用程序,WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!