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.

181 lines
5.6 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 || (HIWORD(dwVersion) < 1922))
  81. {
  82. if (pfnVerSetConditionMask)
  83. {
  84. /* get the condition mask. */
  85. dwlConditionMask = (*pfnVerSetConditionMask)(dwlConditionMask, VER_SUITENAME, VER_AND);
  86. }
  87. else
  88. {
  89. /* we are running older builds of NT5. (pre-1922) */
  90. /* -------------------------------------------------------------
  91. Calling the VerSetConditionMask is the newer way to get the condition mask.
  92. but since this new function was added only on Build 1922,
  93. this will not work for pre-1922 builds (like Beta2) of NT5.
  94. if you want your program to work for pre 1922 builds of NT5 as well.
  95. use
  96. OLD_VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
  97. instead of calling VerSetConditionMask dynamically.
  98. You might want to remove this condition if you dont care about interminent builds of NT5
  99. ------------------------------------------------------------- */
  100. OLD_VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
  101. }
  102. pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ;
  103. if (pfnVerifyVersionInfoA != NULL)
  104. {
  105. ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));
  106. osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);
  107. osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
  108. bResult = (*pfnVerifyVersionInfoA)(
  109. &osVersionInfo,
  110. VER_SUITENAME,
  111. dwlConditionMask);
  112. }
  113. }
  114. }
  115. }
  116. else
  117. {
  118. /* This is NT 40 */
  119. bResult = ValidateProductSuite( "Terminal Server" );
  120. }
  121. }
  122. return bResult;
  123. }
  124. int WINAPI WinMain(
  125. HINSTANCE hInstance, // handle to current instance
  126. HINSTANCE hPrevInstance, // handle to previous instance
  127. LPSTR lpCmdLine, // pointer to command line
  128. int nCmdShow // show state of window);
  129. )
  130. {
  131. BOOL bIsTerminalServer;
  132. UNREFERENCED_PARAMETER (hInstance);
  133. UNREFERENCED_PARAMETER (hPrevInstance);
  134. UNREFERENCED_PARAMETER (lpCmdLine);
  135. UNREFERENCED_PARAMETER (nCmdShow);
  136. bIsTerminalServer = IsTerminalServicesEnabled();
  137. if (bIsTerminalServer)
  138. MessageBoxA( NULL, "Terminal Services is running.", "Status", MB_OK );
  139. else
  140. MessageBoxA( NULL, "Not a Terminal Services box.", "Status", MB_OK );
  141. return 0;
  142. }