WMI查询不返回结果C ++

时间:2015-05-28 05:27:51

标签: c++ wmi win32-process wql

我从Windows 7计算机连接到Windows Server 2012和2008 R2。

我的代码在某些计算机上运行,​​但在某些计算机上运行我的应用程序时,查询始终返回NULL。

当我在IEnumWbemClassObject对象上执行Next方法时,它返回错误代码x80041003。

我试图查询Win32_Process类

我的代码:

 hres =  CoInitializeEx( 0, COINIT_MULTITHREADED  ); 
hres =  CoInitializeSecurity(
        NULL, 
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_CONNECT,       // Default authentication 
        RPC_C_IMP_LEVEL_IMPERSONATE,     // Default Impersonation  
        NULL,                        // Authentication info
        EOAC_NONE,                   // Additional capabilities 
        0                            // Reserved
        );

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

hres = pLoc->ConnectServer( ServerName,Username, Password, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL,    &pSvc);


COAUTHIDENTITY AuthId;
memset(&AuthId, 0, sizeof(COAUTHIDENTITY));
//Initialized AuthId


hres = CoSetProxyBlanket(
                                    pSvc,                           // Indicates the proxy to set
                                    RPC_C_AUTHN_WINNT,          // RPC_C_AUTHN_xxx
                                    RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
                                    NULL,                       // Server principal name 
                                    RPC_C_AUTHN_LEVEL_CALL,         // RPC_C_AUTHN_LEVEL_xxx 
                                    RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
                                    &AuthId,                            // client identity
                                    EOAC_NONE     
                                );

Query.Format( _T( "SELECT * FROM Win32_Process WHERE Name like '%s.exe'" ), App.Name );

    IEnumWbemClassObject* pEnumerator = NULL;

    hr = App.Server.pSvc->ExecQuery(
                            L"WQL", 
                            Query.AllocSysString(),
                            WBEM_FLAG_RETURN_IMMEDIATELY, 
                            NULL,
                            &pEnumerator
                        );

hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

0 个答案:

没有答案