Prev: How long does your ws2008 ts take to log someone on?
Next: TSwebaccess does not show the applications
From: Michael Brednich on 7 May 2010 06:27 Just in case anyone else needs to do this in C++: #include "comutil.h" #include "Wbemidl.h" # pragma comment(lib, "wbemuuid.lib") # pragma comment(lib, "comsuppw.lib") bool HasTerminalServicesRole() { bool bHasTerminalServicesRole = false; // Initialize COM. HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { // Initialize Security hr = CoInitializeSecurity( NULL, -1, // COM negotiates service NULL, // Authentication services NULL, // Reserved RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // authentication RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); if (SUCCEEDED(hr)) { // Obtain the initial locator to Windows Management IWbemLocator *pLocator = NULL; hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator); if (SUCCEEDED(hr)) { IWbemServices *pNamespace = NULL; _bstr_t sNamespace(L"ROOT\\CIMV2"); // Connect to the root\cimv2 namespace with the // current user and obtain pointer // to make IWbemServices calls. hr = pLocator->ConnectServer( sNamespace, // WMI namespace NULL, // User name NULL, // User password 0, // Locale NULL, // Security flags 0, // Authority 0, // Context object &pNamespace // IWbemServices proxy ); if (SUCCEEDED(hr)) { // Set the IWbemServices proxy so that impersonation // of the user (client) occurs. hr = CoSetProxyBlanket( pNamespace, // the proxy to set RPC_C_AUTHN_WINNT, // authentication service RPC_C_AUTHZ_NONE, // authorization service NULL, // Server principal name RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // authentication level RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level NULL, // client identity EOAC_NONE // proxy capabilities ); if(SUCCEEDED(hr)) { IEnumWbemClassObject* pEnumerator = NULL; hr = pNamespace->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_ServerFeature WHERE (ID=130)"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); if(SUCCEEDED(hr)) { IWbemClassObject * pObject = NULL; ULONG uReturn = 0; if (pEnumerator) { hr = pEnumerator->Next(WBEM_INFINITE, 1, &pObject, &uReturn); if(SUCCEEDED(hr) && uReturn > 0) { bHasTerminalServicesRole = true; } } } } } } CoUninitialize(); } } return bHasTerminalServicesRole; }
First
|
Prev
|
Pages: 1 2 Prev: How long does your ws2008 ts take to log someone on? Next: TSwebaccess does not show the applications |