Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
 Detecting Whether Remote Desktop Se...

  Switch on low bandwidth view
Detecting Whether Remote Desktop Services Is Installed

Applications designed for Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, and Windows 2000 can use the VerifyVersionInfo function to detect whether Remote Desktop Services is installed. The following example shows a function that returns a nonzero value if Remote Desktop Services is installed. Note that this code is not compatible with earlier versions of Microsoft Windows.

#include <windows.h>

BOOL AreWeRunningTerminalServices(void)
{
   OSVERSIONINFOEX osVersionInfo;
   DWORDLONG dwlConditionMask = 0;

   ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
   osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;

   VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );

   return VerifyVersionInfo(
      &osVersionInfo,
      VER_SUITENAME,
      dwlConditionMask
      );
}

If your application needs to be binary-compatible with Windows 2000, call the IsTerminalServicesEnabled function to detect Remote Desktop Services. For an example of using the IsTerminalServicesEnabled function, see the code later in this topic. On a system running Windows 2000 or later, this code dynamically links to the VerifyVersionInfo and VerSetConditionMask functions, which it uses to test for the Remote Desktop Services product suite.

#include <windows.h>
#include <winbase.h>

BOOL IsTerminalServicesEnabled( VOID ) 
{
   BOOL    bResult = FALSE;
   DWORD   dwVersion;
   OSVERSIONINFOEXA osVersion;
   DWORDLONG dwlCondition = 0;
   HMODULE hmodK32 = NULL;
   HMODULE hmodNtDll = NULL;
   typedef ULONGLONG (WINAPI *PFnVerSetCondition)
      (ULONGLONG, ULONG, UCHAR);
   typedef BOOL (WINAPI *PFnVerifyVersionA)
      (POSVERSIONINFOEXA, DWORD, DWORDLONG);
   PFnVerSetCondition pfnVerSetCondition;
   PFnVerifyVersionA pfnVerifyVersionA;

   dwVersion = GetVersion();

   // On Windows 2000 and later, use the VerifyVersionInfo and 
   // VerSetConditionMask functions. Don't static link because 
   // it won't load on earlier systems.

   hmodNtDll = GetModuleHandleA( "ntdll.dll" );
   if (hmodNtDll) 
   {
      pfnVerSetCondition = (PFnVerSetCondition) GetProcAddress( 
         hmodNtDll, "VerSetConditionMask");
      if (pfnVerSetCondition != NULL) 
      {
         dwlCondition = (*pfnVerSetCondition) (dwlCondition, 
            VER_SUITENAME, VER_AND);

         // Get a VerifyVersionInfo pointer.

         hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
         if (hmodK32 != NULL) 
         {
            pfnVerifyVersionA = (PFnVerifyVersionA) GetProcAddress(
            hmodK32, "VerifyVersionInfoA") ;
            if (pfnVerifyVersionA != NULL) 
            {
               ZeroMemory(&osVersion, sizeof(osVersion));
               osVersion.dwOSVersionInfoSize = sizeof(osVersion);
               osVersion.wSuiteMask = VER_SUITE_TERMINAL;
               bResult = (*pfnVerifyVersionA) (&osVersion,
               VER_SUITENAME, dwlCondition);
            }
         }
      }
   }

   return bResult;
}

Send comments about this topic to Microsoft

Build date: 6/26/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker