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.

244 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. osver.c
  5. Abstract:
  6. This module contains utility routines for identifying different NT product
  7. version types, suites, and feature attributes.
  8. Author:
  9. Jim Cavalaris (jamesca) 03-07-2001
  10. Environment:
  11. User-mode only.
  12. Revision History:
  13. 07-March-2001 jamesca
  14. Creation and initial implementation.
  15. --*/
  16. //
  17. // includes
  18. //
  19. #include "precomp.h"
  20. #include "umpnpi.h"
  21. //
  22. // global data
  23. //
  24. const TCHAR RegWinlogonKeyName[] =
  25. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
  26. const TCHAR RegAllowMultipleTSSessionsValueName[] =
  27. TEXT("AllowMultipleTSSessions");
  28. BOOL
  29. IsEmbeddedNT(
  30. VOID
  31. )
  32. /*++
  33. Routine Description:
  34. Check if this is Embedded product suite of NT.
  35. Arguments:
  36. None.
  37. Return Value:
  38. Return TRUE / FALSE.
  39. --*/
  40. {
  41. static BOOL bVerified = FALSE;
  42. static BOOL bIsEmbeddedNT = FALSE;
  43. if (!bVerified) {
  44. OSVERSIONINFOEX osvix;
  45. DWORDLONG dwlConditionMask = 0;
  46. ZeroMemory(&osvix, sizeof(OSVERSIONINFOEX));
  47. osvix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  48. osvix.wSuiteMask = VER_SUITE_EMBEDDEDNT;
  49. VER_SET_CONDITION(dwlConditionMask, VER_SUITENAME, VER_OR);
  50. if (VerifyVersionInfo(&osvix,
  51. VER_SUITENAME,
  52. dwlConditionMask)) {
  53. bIsEmbeddedNT = TRUE;
  54. }
  55. bVerified = TRUE;
  56. }
  57. return bIsEmbeddedNT;
  58. } // IsEmbeddedNT
  59. BOOL
  60. IsTerminalServer(
  61. VOID
  62. )
  63. /*++
  64. Routine Description:
  65. Check if Terminal Services are available on this version of NT.
  66. Arguments:
  67. None.
  68. Return Value:
  69. Return TRUE / FALSE.
  70. --*/
  71. {
  72. static BOOL bVerified = FALSE;
  73. static BOOL bIsTerminalServer = FALSE;
  74. if (!bVerified) {
  75. OSVERSIONINFOEX osvix;
  76. DWORDLONG dwlConditionMask = 0;
  77. ZeroMemory(&osvix, sizeof(OSVERSIONINFOEX));
  78. osvix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  79. osvix.wSuiteMask = VER_SUITE_TERMINAL | VER_SUITE_SINGLEUSERTS;
  80. VER_SET_CONDITION(dwlConditionMask, VER_SUITENAME, VER_OR);
  81. if (VerifyVersionInfo(&osvix, VER_SUITENAME, dwlConditionMask)) {
  82. bIsTerminalServer = TRUE;
  83. }
  84. bVerified = TRUE;
  85. }
  86. return bIsTerminalServer;
  87. } // IsTerminalServer
  88. BOOL
  89. IsFastUserSwitchingEnabled(
  90. VOID
  91. )
  92. /*++
  93. Routine Description:
  94. Checks to see if Terminal Services Fast User Switching is enabled. This is
  95. to check if we should use the physical console session for UI dialogs, or
  96. always use session 0.
  97. Fast User Switching exists only on workstation product version, where terminal
  98. services are available, when AllowMultipleTSSessions is set.
  99. On server and above, or when multiple TS users are not allowed, session 0
  100. can only be attached remotely be special request, in which case it should be
  101. considered the "Console" session.
  102. Arguments:
  103. None.
  104. Return Value:
  105. Returns TRUE if Fast User Switching is currently enabled, FALSE otherwise.
  106. --*/
  107. {
  108. static BOOL bVerified = FALSE;
  109. static BOOL bIsTSWorkstation = FALSE;
  110. HKEY hKey;
  111. ULONG ulSize, ulValue;
  112. BOOL bFusEnabled;
  113. //
  114. // Verify the product version if we haven't already.
  115. //
  116. if (!bVerified) {
  117. OSVERSIONINFOEX osvix;
  118. DWORDLONG dwlConditionMask = 0;
  119. ZeroMemory(&osvix, sizeof(OSVERSIONINFOEX));
  120. osvix.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  121. osvix.wProductType = VER_NT_WORKSTATION;
  122. VER_SET_CONDITION(dwlConditionMask, VER_PRODUCT_TYPE, VER_LESS_EQUAL);
  123. osvix.wSuiteMask = VER_SUITE_TERMINAL | VER_SUITE_SINGLEUSERTS;
  124. VER_SET_CONDITION(dwlConditionMask, VER_SUITENAME, VER_OR);
  125. if (VerifyVersionInfo(&osvix,
  126. VER_PRODUCT_TYPE | VER_SUITENAME,
  127. dwlConditionMask)) {
  128. bIsTSWorkstation = TRUE;
  129. }
  130. bVerified = TRUE;
  131. }
  132. //
  133. // Fast user switching (FUS) only applies to the Workstation product where
  134. // Terminal Services are enabled (i.e. Personal, Professional).
  135. //
  136. if (!bIsTSWorkstation) {
  137. return FALSE;
  138. }
  139. //
  140. // Check if multiple TS sessions are currently allowed. We can't make this
  141. // info static because it can change dynamically.
  142. //
  143. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  144. RegWinlogonKeyName,
  145. 0,
  146. KEY_READ,
  147. &hKey) != ERROR_SUCCESS) {
  148. return FALSE;
  149. }
  150. ulValue = 0;
  151. ulSize = sizeof(ulValue);
  152. bFusEnabled = FALSE;
  153. if (RegQueryValueEx(hKey,
  154. RegAllowMultipleTSSessionsValueName,
  155. NULL,
  156. NULL,
  157. (LPBYTE)&ulValue,
  158. &ulSize) == ERROR_SUCCESS) {
  159. bFusEnabled = (ulValue != 0);
  160. }
  161. RegCloseKey(hKey);
  162. return bFusEnabled;
  163. } // IsFastUserSwitchingEnabled
  164.