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.

255 lines
6.1 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. Module Name:
  4. tscomp.cpp
  5. Abstract:
  6. This compatibility dll is used by winnt32.exe in order to decide
  7. whether the user need to be warned about Terminal Server installation on system and it
  8. impending removal
  9. Author:
  10. Makarand Patwardhan (MakarP) 28-Sept-2000
  11. Environment:
  12. compatibility dll for winnt32.exe
  13. Notes:
  14. Revision History:
  15. --*/
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <windows.h>
  20. #include <tchar.h>
  21. #include <comp.h>
  22. #include "registry.h"
  23. #include "tscomprc.h"
  24. HINSTANCE g_hinst;
  25. // compatibility text and html for w2k upgrades.
  26. TCHAR TSCOMP_ERROR_HTML_FILE_5[] = _T("compdata\\tscomp5.htm");
  27. TCHAR TSCOMP_ERROR_TEXT_FILE_5[] = _T("compdata\\tscomp5.txt");
  28. // compatibility text and html for ts4 upgrades.
  29. TCHAR TSCOMP_ERROR_HTML_FILE_4[] = _T("compdata\\tscomp4.htm");
  30. TCHAR TSCOMP_ERROR_TEXT_FILE_4[] = _T("compdata\\tscomp4.txt");
  31. LPCTSTR TS_ENABLED_VALUE = _T("TSEnabled");
  32. LPCTSTR TS_APPCMP_VALUE = _T("TSAppCompat");
  33. LPCTSTR REG_CONTROL_TS_KEY = _T("System\\CurrentControlSet\\Control\\Terminal Server");
  34. LPCTSTR REG_PRODUCT_VER_KEY = _T("ProductVersion");
  35. extern "C"
  36. BOOL WINAPI
  37. DllMain(
  38. HINSTANCE hInstance,
  39. DWORD dwReasonForCall,
  40. LPVOID lpReserved
  41. )
  42. {
  43. BOOL status = TRUE;
  44. switch( dwReasonForCall )
  45. {
  46. case DLL_PROCESS_ATTACH:
  47. g_hinst = hInstance;
  48. DisableThreadLibraryCalls(hInstance);
  49. break;
  50. case DLL_PROCESS_DETACH:
  51. case DLL_THREAD_ATTACH:
  52. case DLL_THREAD_DETACH:
  53. break;
  54. }
  55. return status;
  56. }
  57. BOOL IsAppServerInstalled (BOOL *pbIsTS4)
  58. {
  59. ASSERT(pbIsTS4);
  60. *pbIsTS4 = FALSE;
  61. CRegistry oRegTermsrv;
  62. DWORD dwError;
  63. if (ERROR_SUCCESS == oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY, KEY_READ))
  64. {
  65. DWORD cbVersion = 0;
  66. LPTSTR szVersion = NULL;
  67. //
  68. // Determine if this is a TS 4.0 upgrade.
  69. //
  70. dwError = oRegTermsrv.ReadRegString(REG_PRODUCT_VER_KEY, &szVersion, &cbVersion);
  71. if (ERROR_SUCCESS == dwError)
  72. {
  73. if ((_tcsicmp(szVersion, _T("5.1")) == 0) || (_tcsicmp(szVersion, _T("5.0")) == 0))
  74. {
  75. DWORD dwValue;
  76. //
  77. // this is 50+ TS, now lets check if TS is enabled,
  78. //
  79. if (ERROR_SUCCESS == oRegTermsrv.ReadRegDWord(TS_ENABLED_VALUE, &dwValue) && dwValue == 1)
  80. {
  81. //
  82. // ts was enabled, check the ts mode.
  83. //
  84. if (ERROR_SUCCESS == oRegTermsrv.ReadRegDWord(TS_APPCMP_VALUE, &dwValue))
  85. {
  86. //
  87. // for appserver mode we have this value 1.
  88. //
  89. return (dwValue == 1);
  90. }
  91. else
  92. {
  93. //
  94. // failed to read mode key, this should not happen.
  95. //
  96. ASSERT(FALSE);
  97. // lets us say that is not in AppServer mode.
  98. return FALSE;
  99. }
  100. }
  101. else
  102. {
  103. //
  104. // ts was not enabled, or we failed to get TSEnabled state.
  105. // either way lets us say that is not in AppServer mode.
  106. //
  107. return FALSE;
  108. }
  109. }
  110. else if ((_tcsicmp(szVersion, _T("4.0")) == 0) || (_tcsicmp(szVersion, _T("2.10")) == 0))
  111. {
  112. //
  113. // this is TS40 or similar upgrade,
  114. // it has only app server mode then.
  115. *pbIsTS4 = TRUE;
  116. return TRUE;
  117. }
  118. else
  119. {
  120. //
  121. // ummm, Cant determine the TS mode. this should not happen,
  122. //
  123. ASSERT(FALSE);
  124. //
  125. // could this be older thatn ts4 version?
  126. //
  127. *pbIsTS4 = TRUE;
  128. return TRUE;
  129. }
  130. }
  131. else
  132. {
  133. //
  134. // ummm, Cant determine the TS mode. this should not happen,
  135. //
  136. ASSERT(FALSE);
  137. // lets us say that is not in AppServer mode.
  138. return FALSE;
  139. }
  140. }
  141. else
  142. {
  143. // this is an upgrade from Non TS system
  144. return FALSE;
  145. }
  146. }
  147. BOOL WINAPI
  148. TSCompatibilityCheck(
  149. IN PCOMPAIBILITYCALLBACK CompatibilityCallback,
  150. IN LPVOID Context
  151. )
  152. /*++
  153. Routine Description:
  154. This routine is called by winnt32.exe in order to decide whether
  155. the user should be warn before upgrade because of Terminal Server
  156. in a Windows 2000 system or later.
  157. Arguments:
  158. CompatibilityCallback - Supplies the winnt32 callback
  159. Context - Supplies the compatibility context
  160. Return Value:
  161. FALSE if the installation can continue
  162. TRUE if the user need to be warned
  163. --*/
  164. {
  165. // BUGBUG : does it work for ts4, test it.
  166. COMPATIBILITY_ENTRY ce;
  167. TCHAR description[100];
  168. BOOL bIsTS4 = FALSE;
  169. if (!IsAppServerInstalled(&bIsTS4))
  170. {
  171. // upgrade can go ahead.
  172. return FALSE;
  173. }
  174. //
  175. // otherwise warn about imminent switch to remote admin mode.
  176. //
  177. if (!LoadString(g_hinst, TSCOMP_STR_ABORT_DESCRIPTION, description, 100)) {
  178. description[0] = 0;
  179. }
  180. ZeroMemory((PVOID) &ce, sizeof(COMPATIBILITY_ENTRY));
  181. ce.Description = description;
  182. if (bIsTS4)
  183. {
  184. ce.HtmlName = TSCOMP_ERROR_HTML_FILE_4;
  185. ce.TextName = TSCOMP_ERROR_TEXT_FILE_4;
  186. }
  187. else
  188. {
  189. ce.HtmlName = TSCOMP_ERROR_HTML_FILE_5;
  190. ce.TextName = TSCOMP_ERROR_TEXT_FILE_5;
  191. }
  192. ce.RegKeyName = NULL;
  193. ce.RegValName = NULL;
  194. ce.RegValDataSize = 0;
  195. ce.RegValData = NULL;
  196. ce.SaveValue = NULL;
  197. ce.Flags = 0;
  198. CompatibilityCallback(&ce, Context);
  199. return TRUE;
  200. }