Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.3 KiB

  1. // Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include <windows.h>
  3. #include <winbase.h>
  4. /* -------------------------------------------------------------
  5. Note that the ValidateProductSuite() and IsTerminalServices()
  6. APIs use ANSI versions of functions in order to maintain
  7. compatibility with Win9X platforms.
  8. ------------------------------------------------------------- */
  9. #ifndef UNREFERENCED_PARAMETER
  10. #define UNREFERENCED_PARAMETER(P) (P)
  11. #endif
  12. #define OLD_VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  13. BOOL ValidateProductSuite (LPSTR SuiteName)
  14. {
  15. BOOL rVal = FALSE;
  16. LONG Rslt;
  17. HKEY hKey = NULL;
  18. DWORD Type = 0;
  19. DWORD Size = 0;
  20. LPSTR ProductSuite = NULL;
  21. LPSTR p;
  22. Rslt = RegOpenKeyA(
  23. HKEY_LOCAL_MACHINE,
  24. "System\\CurrentControlSet\\Control\\ProductOptions",
  25. &hKey
  26. );
  27. if (Rslt != ERROR_SUCCESS)
  28. goto exit;
  29. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type, NULL, &Size );
  30. if (Rslt != ERROR_SUCCESS || !Size)
  31. goto exit;
  32. ProductSuite = (LPSTR) LocalAlloc( LPTR, Size );
  33. if (!ProductSuite)
  34. goto exit;
  35. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type,
  36. (LPBYTE) ProductSuite, &Size );
  37. if (Rslt != ERROR_SUCCESS || Type != REG_MULTI_SZ)
  38. goto exit;
  39. p = ProductSuite;
  40. while (*p)
  41. {
  42. if (lstrcmpA( p, SuiteName ) == 0)
  43. {
  44. rVal = TRUE;
  45. break;
  46. }
  47. p += (lstrlenA( p ) + 1);
  48. }
  49. exit:
  50. if (ProductSuite)
  51. LocalFree( ProductSuite );
  52. if (hKey)
  53. RegCloseKey( hKey );
  54. return rVal;
  55. }
  56. BOOL IsTerminalServicesEnabled( VOID )
  57. {
  58. BOOL bResult = FALSE;
  59. DWORD dwVersion;
  60. OSVERSIONINFOEXA osVersionInfo;
  61. DWORDLONG dwlConditionMask = 0;
  62. HMODULE hmodK32 = NULL;
  63. typedef ULONGLONG (*PFnVerSetConditionMask) ( ULONGLONG, ULONG, UCHAR );
  64. typedef BOOL (*PFnVerifyVersionInfoA) (POSVERSIONINFOEXA, DWORD, DWORDLONG);
  65. PFnVerSetConditionMask pfnVerSetConditionMask;
  66. PFnVerifyVersionInfoA pfnVerifyVersionInfoA;
  67. dwVersion = GetVersion();
  68. /* are we running NT ? */
  69. if (!(dwVersion & 0x80000000))
  70. {
  71. // Is it NT 50 or greater ?
  72. if (LOBYTE(LOWORD(dwVersion)) > 4)
  73. {
  74. /* In NT5 we need to use the Product Suite APIs
  75. Don't static link because it won't load on non-NT5 systems */
  76. hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
  77. if (hmodK32)
  78. {
  79. pfnVerSetConditionMask = (PFnVerSetConditionMask )GetProcAddress( hmodK32, "VerSetConditionMask");
  80. if (pfnVerSetConditionMask)
  81. {
  82. /* get the condition mask. */
  83. dwlConditionMask = (*pfnVerSetConditionMask)(dwlConditionMask, VER_SUITENAME, VER_AND);
  84. pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ;
  85. if (pfnVerifyVersionInfoA != NULL)
  86. {
  87. ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));
  88. osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);
  89. osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
  90. bResult = (*pfnVerifyVersionInfoA)(
  91. &osVersionInfo,
  92. VER_SUITENAME,
  93. dwlConditionMask);
  94. }
  95. }
  96. }
  97. }
  98. else
  99. {
  100. /* This is NT 40 */
  101. bResult = ValidateProductSuite( "Terminal Server" );
  102. }
  103. }
  104. return bResult;
  105. }
  106. int WINAPI WinMain(
  107. HINSTANCE hInstance,
  108. HINSTANCE hPrevInstance,
  109. LPSTR lpCmdLine,
  110. int nCmdShow
  111. )
  112. {
  113. BOOL bIsTerminalServer;
  114. UNREFERENCED_PARAMETER (hInstance);
  115. UNREFERENCED_PARAMETER (hPrevInstance);
  116. UNREFERENCED_PARAMETER (lpCmdLine);
  117. UNREFERENCED_PARAMETER (nCmdShow);
  118. bIsTerminalServer = IsTerminalServicesEnabled();
  119. if (bIsTerminalServer)
  120. MessageBoxA( NULL, "Terminal Services is running.", "Status", MB_OK );
  121. else
  122. MessageBoxA( NULL, "Not a Terminal Services box.", "Status", MB_OK );
  123. return 0;
  124. }