在使用利用 WMI 功能获取计算机系统信息的脚本的时候,往往会出现“runtime error permission denied getobject”这样的错误,下面分 Win2000 和 Win2003 平台分别说明解决的方法。

Win2000

运行 dcomcnfg 命令

重启 COM+ Event System 和 Windows Managemetn Instrumentation 服务。

Win2003

运行 dcomcnfg 命令

如图,选中 My Computer 的 Properities,

Check “Enable Distributed COM on this computer”。

重启 COM+ Event System 和 Windows Managemetn Instrumentation 服务。

##################################

个人声明:此中文章皆为原创,如有转载但请注明出处,谢谢!!
批评与建议请联系:simpleman.xu#gmail.com

#################################

Random Posts: (Automatically Generated)

Tags: , , , ,

3 Comments on 利用 wmi 获取计算机信息时出现“runtime error permission denied getobject”的解决

  1. binggong says:

    好的,多谢了。希望您那如果有懂的,能告诉我下。愉快!

    [Reply]

  2. binggong says:

    我用的是vc6,具体代码如下,在这里面显示的格式比较乱,希望您能看懂,盼您的解答,谢谢!
    void setWmi()
    {
    HRESULT hRes = 0;
    IWbemClassObject *pProcess = NULL;
    IWbemClassObject *pOutInst = NULL;
    //IWbemClassObject *pInParameters;
    IWbemClassObject *pMethodObject;
    _variant_t ip = "172.19.15.99";

    IWbemLocator *pWbemLocator = NULL;
    int val = 0;

    //CHAR name[32] = "10.191.4.147\0";
    COSERVERINFO cs;
    // Init structures to zero
    memset(&cs, 0, sizeof(cs));
    // Allocate the server name in the COSERVERINFO struct
    // use _bstr_t copy constructor
    cs.pwszName = _bstr_t("10.191.4.187");
    //cs.pwszName = _bstr_t("10.191.4.147");

    MULTI_QI qi[1];
    // Array of structures set to zero
    memset(qi, 0, sizeof(qi));

    // Fill the qi with a valid interface
    qi[0].pIID = &IID_IWbemLocator;
    if(CoCreateInstanceEx(CLSID_WbemLocator, NULL,
    CLSCTX_INPROC_SERVER,//|CLSCTX_REMOTE_SERVER,// CLSCTX_REMOTE_SERVER|CLSCTX_INPROC_SERVER,
    &cs, 1, qi) == S_OK)
    {
    IWbemServices *m_pIWbemServices = NULL;
    BSTR wsNamespace = SysAllocString(L"\\\\10.191.4.187\\root\\inventec\\esms");
    //BSTR wsNamespace = SysAllocString(L"\\\\10.191.4.147\\root\\inventec\\esms");
    pWbemLocator = (IWbemLocator *)qi[0].pItf;

    hRes = pWbemLocator->ConnectServer(wsNamespace,
    //SysAllocString(L"itc207019"),
    //SysAllocString(L"13821132753"),
    //SysAllocString(L"ningkai2004"),
    SysAllocString(L"administrator"),
    SysAllocString(L"111111"),
    //SysAllocString(L"123qwe!"),
    //_bstr_t(L"MS_409"),
    NULL,
    0,
    //_bstr_t(L"ntlmdomain:itc"),
    _bstr_t(L"ntlmdomain:ESM-2"),
    NULL,
    &m_pIWbemServices);
    if (FAILED(hRes))
    {
    //pSvc->Release();
    //pLoc->Release();
    CoUninitialize();
    return; // Program has failed.
    }

    hRes = CoSetProxyBlanket(m_pIWbemServices,
    RPC_C_AUTHN_WINNT,
    RPC_C_AUTHZ_NONE,
    NULL,
    RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
    //RPC_C_AUTHN_LEVEL_PKT,
    RPC_C_IMP_LEVEL_IDENTIFY,
    NULL,
    EOAC_NONE
    );

    if (FAILED(hRes))
    {
    //pSvc->Release();
    //pLoc->Release();
    CoUninitialize();
    return; // Program has failed.
    }

    if(hRes == S_OK)
    {
    //ESMSPXE
    //IWbemCallResult *result;
    hRes = m_pIWbemServices->GetObject(SysAllocString(L"ESMSPXE"),
    //WBEM_FLAG_DIRECT_READ,
    0,
    NULL,
    &pProcess,
    NULL);
    if(FAILED(hRes))
    {
    m_pIWbemServices->Release();
    pWbemLocator->Release();
    CoUninitialize();
    //GetErrorInfo
    return;
    }
    //IWbemClassObject pInParameter;
    IWbemClassObject *pInParameters;
    hRes = pProcess->GetMethod((L"changeIP"),
    0,
    &pInParameters,
    NULL);
    if(FAILED(hRes))
    {
    return;
    }
    hRes = pInParameters->SpawnInstance(0, &pMethodObject);
    if(FAILED(hRes))
    {
    return;
    }
    hRes = pMethodObject->Put(_bstr_t(L"ServerIP"),
    0,
    &ip,
    NULL);
    if(FAILED(hRes))
    {
    return;
    }
    hRes = m_pIWbemServices->ExecMethod(SysAllocString(L"ESMSPXE"),
    SysAllocString(L"changeIp"),
    0,
    NULL,
    pMethodObject,
    &pOutInst,
    NULL);
    if(FAILED(hRes))
    {
    return;
    }

    pProcess->Release();
    pOutInst->Release();

    }
    }
    }

    [Reply]

  3. binggong says:

    hi,我遇到了关于DCOM的问题,ConnectServer接口函数已经调用成功,但是在调用接口函数GetObject的时候返回值为0×80070005 (DCOM ACCESS_DENIED)。不知道您遇到过这种情况没?
    博主 对 binggong 的回复: 2008-01-23 21:21:51
    I’m sorry! I’m just an network engineer, and not good at computer language. Maybe you can find related information in http://msdn2.microsoft.com/

    [Reply]

Leave a Reply

*