Windows Cosole应用程序,WMI [英] Windows Cosole Application, WMI

查看:85
本文介绍了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);

推荐答案

假定您具有源代码和.map或.pdb文件,则可以查找地址0x00a11e5e对应的内容. Microsoft知识库文章如何通过使用错误中的地址来识别代码中发生错误的位置,对此有更多信息.您收到的消息 [^ ].

否则,我建议调试构建和调试会话.

提交代码后进行您不在任何地方检查HRESULTS.这是为什么?该错误信息表明您正在某处取消引用空指针.检查返回值.
Assuming you have the source code, and a .map or .pdb file, you can look up what the address 0x00a11e5e corresponds to. There is more information about this in the Microsoft knowledge base article How to identify where a failure is occurring in your code by using the address in the error message that you receive[^].

Otherwise I recommend a debug build and a debug session.

Edit after code was submitted: You are not checking the HRESULTS anywhere. Why is that? The error message says you are dereferencing a null pointer somewhere. Check the return values.


这篇关于Windows Cosole应用程序,WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆