Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394450%28v=vs.85%29.aspx" rel="nofollow"><code>MSDN</code></a> documentation states, the <code>Win32_SID</code> WMI class cannot be enumerated.</p> <p>So, you cannot use the ExecQuery method, instead use the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa392109%28v=vs.85%29.aspx" rel="nofollow"><code>IWbemServices::GetObject</code></a> function passing the proper WMI <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa390350%28v=vs.85%29.aspx" rel="nofollow"><code>object path</code></a>. something like <code>Win32_SID.SID='S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334'</code></p> <p>Try this sample</p> <pre><code>#include "stdafx.h" #define _WIN32_DCOM #include &lt;iostream&gt; using namespace std; #include &lt;comdef.h&gt; #include &lt;Wbemidl.h&gt; # pragma comment(lib, "wbemuuid.lib") #pragma argsused int main(int argc, char* argv[]) { BSTR strNetworkResource; strNetworkResource = L"\\\\.\\root\\CIMV2"; // Initialize COM. ------------------------------------------ HRESULT hres; hres = CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hres)) { cout &lt;&lt; "Failed to initialize COM library. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } // 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_IMPERSONATE, // Default Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); if (FAILED(hres)) { cout &lt;&lt; "Failed to initialize security. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } // Obtain the initial locator to WMI ------------------------- IWbemLocator *pLoc = NULL; hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &amp;pLoc); if (FAILED(hres)) { cout &lt;&lt; "Failed to create IWbemLocator object." &lt;&lt; " Err code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } // Connect to WMI through the IWbemLocator::ConnectServer method IWbemServices *pSvc = NULL; hres = pLoc-&gt;ConnectServer( _bstr_t(strNetworkResource), // Object path of WMI namespace NULL, // User name. NULL = current user NULL, // User password. NULL = current 0, // Locale. NULL indicates current NULL, // Security flags. 0, // Authority (e.g. Kerberos) 0, // Context object &amp;pSvc // pointer to IWbemServices proxy ); if (FAILED(hres)) { cout &lt;&lt; "Could not connect. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; pLoc-&gt;Release(); CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } cout &lt;&lt; "Connected to root\\CIMV2 WMI namespace" &lt;&lt; endl; // Set security levels on the proxy ------------------------- hres = CoSetProxyBlanket( pSvc, // Indicates the proxy to set RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx RPC_C_AUTHZ_NONE, // 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 NULL, // client identity EOAC_NONE // proxy capabilities ); if (FAILED(hres)) { cout &lt;&lt; "Could not set proxy blanket. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; pSvc-&gt;Release(); pLoc-&gt;Release(); CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } // Use the IWbemServices pointer to make requests of WMI ---- IWbemClassObject *pclsObj = NULL; hres = pSvc-&gt;GetObject(L"Win32_SID.SID='S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334'", 0, NULL, &amp;pclsObj, NULL); if (FAILED(hres)) { cout &lt;&lt; "GetObject failed" &lt;&lt; " Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl; cout &lt;&lt; _com_error(hres).ErrorMessage() &lt;&lt; endl; pSvc-&gt;Release(); pLoc-&gt;Release(); CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 1; // Program has failed. } else { VARIANT vtProp; HRESULT hr = pclsObj-&gt;Get(L"AccountName", 0, &amp;vtProp, 0, 0);// String if (!FAILED(hr)) { if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY)) wcout &lt;&lt; "AccountName : " &lt;&lt; ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") &lt;&lt; endl; else wcout &lt;&lt; "AccountName : " &lt;&lt; vtProp.bstrVal &lt;&lt; endl; } VariantClear(&amp;vtProp); pclsObj-&gt;Release(); pclsObj=NULL; } // Cleanup pSvc-&gt;Release(); pLoc-&gt;Release(); if (pclsObj!=NULL) pclsObj-&gt;Release(); CoUninitialize(); cout &lt;&lt; "press enter to exit" &lt;&lt; endl; cin.get(); return 0; // Program successfully completed. } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload