【问题标题】:Is it possible to query to WMI on a Remote Computer for MicrosoftTPM namespace? [Remote WMI query to Win32_Tpm class failed with, HRESULT 0x80041013]是否可以在远程计算机上为 MicrosoftTPM 命名空间查询 WMI? [对 Win32_Tpm 类的远程 WMI 查询失败,HRESULT 0x80041013]
【发布时间】:2023-04-07 14:24:02
【问题描述】:

我正在尝试从远程机器查询 WMI 的 Win32_Tpm 类。但它失败并显示 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。

下面是详细代码,

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);   

【问题讨论】:

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


    【解决方案1】:

    上面的类名是函数 CreateInstanceEnum() 中的 L"Win32_Tpm"。 我可以在从本地机器访问时获取实例,但在从远程机器访问时失败。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-14
      • 2014-08-17
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多