是否可以在远程计算机上查询Microsoft TPM名称空间的WMI? [Win32_Tpm类的远程WMI查询失败,HRESULT 0x80041013]

时间:2015-03-17 14:43:33

标签: wmi remote-access wmi-query dcom tpm

我正在尝试从远程机器查询Win32_Tpm类的WMI。但它失败了HRESULT 0x80041013&描述:提供程序加载失败。 是否可以远程访问MicrosoftTPM命名空间? 以下是代码,

hres = pSvc ->CreateInstanceEnum(
    bstr_t(Class),
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    NULL,
    &Enumerator);

hres = CoSetProxyBlanket(
    Enumerator,                    // Indicates the proxy to set
    RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
    RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
    COLE_DEFAULT_PRINCIPAL,         // Server principal name 
    RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx 
    RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
    mUserAcct,                       // client identity
    EOAC_NONE                       // proxy capabilities 
    );

    hres = Enumerator->Next(WBEM_INFINITE, 1, &TPMClass, &uReturn);   

//这里我失败的是hres = 0x80041013和uReturn = 0,执行上述语句后TPMClass的值为NULL。

Bellow是详细代码,

IEnumWbemClassObject* Enumerator;
IWbemClassObject* TPMClass = NULL;
ULONG uReturn = 0;

hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
    cout << "Failed to initialize COM library. Error code = 0x"
        << hex << hres << endl;
    return 1;                  // Program has failed.
}

// Step 2: --------------------------------------------------
// Set general COM security levels --------------------------

hres = CoInitializeSecurity(
    NULL,
    -1,                          // COM authentication
    NULL,                        // Authentication services
    NULL,                        // Reserved
    RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
    RPC_C_IMP_LEVEL_IDENTIFY,    // Default Impersonation  
    NULL,                        // Authentication info
    EOAC_NONE,                   // Additional capabilities 
    NULL                         // Reserved
    );


if (FAILED(hres))
{
    cout << "Failed to initialize security. Error code = 0x"
        << hex << hres << endl;
    CoUninitialize();
    return 1;                    // Program has failed.
}

// Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI -------------------------

IWbemLocator *pLoc = NULL;

hres = CoCreateInstance(
    CLSID_WbemLocator,
    0,
    CLSCTX_INPROC_SERVER,
    IID_IWbemLocator, (LPVOID *)&pLoc);

if (FAILED(hres))
{
    cout << "Failed to create IWbemLocator object."
        << " Err code = 0x"
        << hex << hres << endl;
    CoUninitialize();
    return 1;                 // Program has failed.
}

// Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method

IWbemServices *pSvc = NULL;

hres = pLoc->ConnectServer(
    _bstr_t(L"\\\\REMOTE\\root\\cimv2\\Security\\MicrosoftTpm"),
    _bstr_t(useToken ? NULL : pszName),    // User name
    _bstr_t(useToken ? NULL : pszPwd),     // User password
    NULL,                              // Locale             
    NULL,                              // Security flags
    _bstr_t(useNTLM ? NULL : pszAuthority),// Authority        
    NULL,                              // Context object 
    &pSvc                              // IWbemServices proxy
    );

COAUTHIDENTITY *userAcct = NULL;
COAUTHIDENTITY authIdent;

//Created COAUTHIDENTITY  with internal function
    userAcct = &authIdent;

hres = CoSetProxyBlanket(
    pSvc,                           // Indicates the proxy to set
    RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
    RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
    COLE_DEFAULT_PRINCIPAL,         // Server principal name 
    RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx 
    RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
    userAcct,                       // client identity
    EOAC_NONE                       // proxy capabilities 
    );

hres = pSvc ->CreateInstanceEnum(
    bstr_t(Class),
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    NULL,
    &Enumerator);

hres = CoSetProxyBlanket(
    Enumerator,                    // Indicates the proxy to set
    RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
    RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
    COLE_DEFAULT_PRINCIPAL,         // Server principal name 
    RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx 
    RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
    mUserAcct,                       // client identity
    EOAC_NONE                       // proxy capabilities 
    );

    //Here I am failing , value of TPMClass is NULL after execution of      following statement also.

    hres = Enumerator->Next(WBEM_INFINITE, 1, &TPMClass, &uReturn);   

1 个答案:

答案 0 :(得分:0)

以上课程名称为L&#34; Win32_Tpm&#34;在函数CreateInstanceEnum()中。 我可以在从本地计算机访问时获取实例,但从远程计算机访问时失败。

注意:我已为远程机器上的用户分配了适当的权限。