Leaked source code of windows server 2003
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.

874 lines
26 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. //
  3. // SubToggle.cpp
  4. // subcomponent enable terminal server implementation.
  5. //
  6. #include "stdafx.h"
  7. #include "SubToggle.h"
  8. #include "hydraoc.h"
  9. #include "pages.h"
  10. #include "secupgrd.h"
  11. #include "gpedit.h"
  12. #pragma warning(push, 4)
  13. // {0F6B957D-509E-11d1-A7CC-0000F87571E3}
  14. DEFINE_GUID(CLSID_PolicySnapInMachine,0xf6b957d, 0x509e, 0x11d1, 0xa7, 0xcc, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3);
  15. // #define REGISTRY_EXTENSION_GUID { 0x35378EAC, 0x683F, 0x11D2, 0xA8, 0x9A, 0x00, 0xC0, 0x4F, 0xBB, 0xCF, 0xA2 }
  16. DEFINE_GUID(CLSID_RegistryEntensionGuid, 0x35378EAC, 0x683F, 0x11D2, 0xA8, 0x9A, 0x00, 0xC0, 0x4F, 0xBB, 0xCF, 0xA2);
  17. GUID guidRegistryEntension = REGISTRY_EXTENSION_GUID;
  18. GUID guidPolicyMachineSnapin = CLSID_PolicySnapInMachine;
  19. //
  20. // Globals
  21. //
  22. extern DefSecPageData *gpSecPageData;
  23. DWORD SubCompToggle::GetStepCount () const
  24. {
  25. return 4;
  26. }
  27. DWORD SubCompToggle::OnQueryState ( UINT uiWhichState ) const
  28. {
  29. DWORD dwReturn = SubcompUseOcManagerDefault;
  30. switch(uiWhichState)
  31. {
  32. case OCSELSTATETYPE_FINAL:
  33. dwReturn = StateObject.IsItAppServer() ? SubcompOn : SubcompOff;
  34. break;
  35. case OCSELSTATETYPE_ORIGINAL:
  36. //
  37. // thought originally the comp was on, we want to unselect it for server sku.
  38. //
  39. if (StateObject.CanInstallAppServer())
  40. {
  41. dwReturn = StateObject.WasItAppServer() ? SubcompOn : SubcompOff;
  42. }
  43. else
  44. {
  45. if (StateObject.WasItAppServer())
  46. {
  47. LogErrorToSetupLog(OcErrLevWarning, IDS_STRING_TERMINAL_SERVER_UNINSTALLED);
  48. }
  49. dwReturn = SubcompOff;
  50. }
  51. break;
  52. case OCSELSTATETYPE_CURRENT:
  53. //
  54. // our state object knows best about the current state for unattended and fresh install cases.
  55. //
  56. if (StateObject.IsTSFreshInstall() || StateObject.IsUnattended())
  57. {
  58. if (StateObject.CurrentTSMode() == eAppServer)
  59. {
  60. dwReturn = SubcompOn;
  61. }
  62. else
  63. {
  64. dwReturn = SubcompOff;
  65. }
  66. }
  67. else
  68. {
  69. dwReturn = SubcompUseOcManagerDefault;
  70. }
  71. break;
  72. default:
  73. AssertFalse();
  74. break;
  75. }
  76. return dwReturn;
  77. }
  78. BOOL IsIeHardforUserSelected()
  79. {
  80. const TCHAR STRING_IEUSER_HARD[] = _T("IEHardenUser");
  81. return GetHelperRoutines().QuerySelectionState(GetHelperRoutines().OcManagerContext,
  82. STRING_IEUSER_HARD, OCSELSTATETYPE_CURRENT);
  83. }
  84. DWORD SubCompToggle::OnQuerySelStateChange (BOOL bNewState, BOOL bDirectSelection) const
  85. {
  86. //
  87. // We dont have problems with somebody disabling TS.
  88. //
  89. if (!bNewState)
  90. return TRUE;
  91. //
  92. // this component is available only for adv server or highter. so dont let it be selected for
  93. // any other sku.
  94. //
  95. if (!StateObject.CanInstallAppServer())
  96. return FALSE;
  97. //
  98. // if its not a user selection let it go through.
  99. //
  100. if (!bDirectSelection)
  101. return TRUE;
  102. if (!IsIeHardforUserSelected())
  103. {
  104. return TRUE;
  105. }
  106. // IDS_IEHARD_EXCLUDES_TS "Internet Explorer Enhanced Security for Users on a Terminal Server will substantially limit the users ability to browse the internet from their Terminal Server sessions\n\nContinue the install with this combination?"
  107. // IDS_DIALOG_CAPTION_CONFIG_WARN "Configuration Warning"
  108. if ( IDYES == DoMessageBox(IDS_IEHARD_EXCLUDES_TS, IDS_DIALOG_CAPTION_CONFIG_WARN, MB_YESNO | MB_ICONEXCLAMATION))
  109. {
  110. return TRUE;
  111. }
  112. else
  113. {
  114. return FALSE;
  115. }
  116. ASSERT(FALSE);
  117. return TRUE;
  118. }
  119. LPCTSTR SubCompToggle::GetSectionToBeProcessed (ESections eSection) const
  120. {
  121. //
  122. // If the state hasn't changed in stand alone setup, don't do anything.
  123. // Note that an permission settings will be handled later.
  124. //
  125. if ((StateObject.CurrentTSMode() == StateObject.OriginalTSMode()) &&
  126. StateObject.IsStandAlone())
  127. {
  128. return(NULL);
  129. }
  130. //
  131. // There are no files to install.
  132. //
  133. if ((eSection == kFileSection) || (eSection == kDiskSpaceAddSection))
  134. {
  135. return(NULL);
  136. }
  137. ETSMode eMode = StateObject.CurrentTSMode();
  138. if (StateObject.IsX86())
  139. {
  140. switch (eMode)
  141. {
  142. case eRemoteAdmin:
  143. return StateObject.IsWorkstation() ? REMOTE_ADMIN_PRO_X86 : REMOTE_ADMIN_SERVER_X86;
  144. break;
  145. case eAppServer:
  146. return StateObject.IsWorkstation() ? APPSERVER_PRO_X86 : APPSERVER_SERVER_X86;
  147. break;
  148. case ePersonalTS:
  149. return StateObject.IsWorkstation() ? PERSONALTS_PRO_X86 : PERSONALTS_SERVER_X86;
  150. break;
  151. case eTSDisabled:
  152. default:
  153. ASSERT(FALSE);
  154. return NULL;
  155. }
  156. }
  157. else
  158. {
  159. switch (eMode)
  160. {
  161. case eRemoteAdmin:
  162. if (StateObject.IsAMD64())
  163. {
  164. return StateObject.IsWorkstation() ? REMOTE_ADMIN_PRO_AMD64 : REMOTE_ADMIN_SERVER_AMD64;
  165. }
  166. else
  167. {
  168. return StateObject.IsWorkstation() ? REMOTE_ADMIN_PRO_IA64 : REMOTE_ADMIN_SERVER_IA64;
  169. }
  170. break;
  171. case eAppServer:
  172. if (StateObject.IsAMD64())
  173. {
  174. return StateObject.IsWorkstation() ? APPSERVER_PRO_AMD64 : APPSERVER_SERVER_AMD64;
  175. }
  176. else
  177. {
  178. return StateObject.IsWorkstation() ? APPSERVER_PRO_IA64 : APPSERVER_SERVER_IA64;
  179. }
  180. break;
  181. case ePersonalTS:
  182. if (StateObject.IsAMD64())
  183. {
  184. return StateObject.IsWorkstation() ? PERSONALTS_PRO_AMD64 : PERSONALTS_SERVER_AMD64;
  185. }
  186. else
  187. {
  188. return StateObject.IsWorkstation() ? PERSONALTS_PRO_IA64 : PERSONALTS_SERVER_IA64;
  189. }
  190. break;
  191. case eTSDisabled:
  192. default:
  193. ASSERT(FALSE);
  194. return NULL;
  195. }
  196. }
  197. }
  198. BOOL SubCompToggle::BeforeCompleteInstall ()
  199. {
  200. if (StateObject.IsItAppServer() != StateObject.WasItAppServer())
  201. {
  202. SetProgressText(StateObject.IsItAppServer() ? IDS_STRING_PROGRESS_ENABLING : IDS_STRING_PROGRESS_DISABLING);
  203. }
  204. return TRUE;
  205. }
  206. LPCTSTR SubCompToggle::GetSubCompID () const
  207. {
  208. return (APPSRV_COMPONENT_NAME);
  209. }
  210. BOOL SubCompToggle::AfterCompleteInstall ()
  211. {
  212. LOGMESSAGE0(_T("Entering AfterCompleteInstall"));
  213. ASSERT(StateObject.Assert());
  214. StateObject.LogState();
  215. WriteLicensingMode();
  216. Tick();
  217. SetPermissionsMode ();
  218. Tick();
  219. //
  220. // this need to be done even if there is no state change, as we want to do this on upgrades as well.
  221. //
  222. if (StateObject.IsStandAlone() && !StateObject.IsStandAloneModeSwitch ())
  223. {
  224. //
  225. // nothing has changed. dont bother to do any of the next steps.
  226. //
  227. return TRUE;
  228. }
  229. WriteModeSpecificRegistry();
  230. Tick();
  231. UpdateMMDefaults();
  232. Tick();
  233. ResetWinstationSecurity ();
  234. Tick();
  235. ModifyWallPaperPolicy();
  236. Tick();
  237. ModifyAppPriority();
  238. AddStartupPopup();
  239. Tick();
  240. // this really belongs in subcore, but since we want to it after ResetWinstationSecurity is called we are calling it here.
  241. //
  242. // we have modified winstation security mechanism for whistler.
  243. // Call this routine, which takes care of upgrades as well as clean installs.
  244. //
  245. LOGMESSAGE0(_T("Will Call SetupWorker now."));
  246. DWORD dwError = SetupWorker(StateObject);
  247. LOGMESSAGE0(_T("Done with SetupWorker."));
  248. if (dwError != ERROR_SUCCESS)
  249. {
  250. LOGMESSAGE1(_T("ERROR :SetupWorker failed. ErrorCode = %d"), dwError);
  251. }
  252. if( StateObject.IsGuiModeSetup() )
  253. {
  254. // WARNING : this must be done after SetupWorker()
  255. SetupRunOnce( GetComponentInfHandle(), RUNONCE_SECTION_KEYWORD );
  256. }
  257. //
  258. // We need a reboot if we toggled TS through AR/P.
  259. //
  260. if ( StateObject.IsStandAlone() && StateObject.IsStandAloneModeSwitch())
  261. {
  262. SetReboot();
  263. //
  264. // If we're changing into or out of app-compatibility mode, inform
  265. // the licensing system, because we're about to reboot
  266. //
  267. InformLicensingOfModeChange();
  268. Tick();
  269. }
  270. ASSERT(StateObject.Assert());
  271. StateObject.LogState();
  272. return(TRUE);
  273. }
  274. BOOL SubCompToggle::WriteLicensingMode ()
  275. {
  276. LOGMESSAGE0(_T("Entering WriteLicensingMode"));
  277. //
  278. // we need to write this value only if it's set in answer file
  279. //
  280. if (StateObject.IsItAppServer() && (StateObject.NewLicMode() != eLicUnset))
  281. {
  282. DWORD dwError;
  283. CRegistry oRegTermsrv;
  284. dwError = oRegTermsrv.CreateKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_LICENSING_KEY);
  285. if (ERROR_SUCCESS == dwError)
  286. {
  287. DWORD dwMode = StateObject.NewLicMode();
  288. TCHAR *tszValueName = StateObject.IsItAppServer() ? REG_LICENSING_MODE_AC_ON : REG_LICENSING_MODE_AC_OFF;
  289. LOGMESSAGE2(_T("Writing %s = %d"), tszValueName, dwMode);
  290. dwError = oRegTermsrv.WriteRegDWord(tszValueName, dwMode);
  291. if (ERROR_SUCCESS == dwError)
  292. {
  293. return TRUE;
  294. }
  295. else
  296. {
  297. LOGMESSAGE2(_T("Error (%d), Writing, %s Value"), dwError, tszValueName);
  298. return FALSE;
  299. }
  300. }
  301. else
  302. {
  303. LOGMESSAGE2(_T("Error (%d), Opening , %s key"), dwError, REG_CONTROL_TS_LICENSING_KEY);
  304. return FALSE;
  305. }
  306. }
  307. else
  308. {
  309. return TRUE;
  310. }
  311. }
  312. BOOL SubCompToggle::ApplySection (LPCTSTR szSection)
  313. {
  314. DWORD dwError;
  315. LOGMESSAGE1(_T("Setting up Registry from section = %s"), szSection);
  316. dwError = SetupInstallFromInfSection(
  317. NULL, // hwndOwner
  318. GetComponentInfHandle(), // inf handle
  319. szSection, //
  320. SPINST_REGISTRY, // operation flags
  321. NULL, // relative key root
  322. NULL, // source root path
  323. 0, // copy flags
  324. NULL, // callback routine
  325. NULL, // callback routine context
  326. NULL, // device info set
  327. NULL // device info struct
  328. );
  329. if (dwError == 0)
  330. {
  331. LOGMESSAGE1(_T("ERROR:while installating section <%lu>"), GetLastError());
  332. }
  333. return (dwError != 0);
  334. }
  335. BOOL SubCompToggle::ResetWinstationSecurity ()
  336. {
  337. //
  338. // If the TS mode is changing, reset winstation securities.
  339. //
  340. DWORD dwError;
  341. if (StateObject.IsAppSrvModeSwitch() && gpSecPageData->GetWinStationCount() > 0)
  342. {
  343. CRegistry pReg;
  344. CRegistry pSubKey;
  345. LPTSTR* pWinStationArray = gpSecPageData->GetWinStationArray();
  346. UINT cArray = gpSecPageData->GetWinStationCount();
  347. LOGMESSAGE1(_T("%d WinStations to reset."), cArray);
  348. //
  349. // Open the WinStations key. At this point, this key must exist.
  350. //
  351. VERIFY(pReg.OpenKey(HKEY_LOCAL_MACHINE, REG_WINSTATION_KEY) == ERROR_SUCCESS);
  352. if (cArray != 0)
  353. {
  354. ASSERT(pWinStationArray != NULL);
  355. for (UINT i = 0; i < cArray; i++)
  356. {
  357. LOGMESSAGE1(_T("Resetting %s."), pWinStationArray[i]);
  358. dwError = pSubKey.OpenKey(pReg, pWinStationArray[i]);
  359. if (dwError == ERROR_SUCCESS)
  360. {
  361. LOGMESSAGE2(_T("Delete registry value %s\\%s"), pWinStationArray[i], REG_SECURITY_VALUE);
  362. dwError = pSubKey.DeleteValue(REG_SECURITY_VALUE);
  363. if (dwError == ERROR_SUCCESS)
  364. {
  365. LOGMESSAGE0(_T("Registry value deleted."));
  366. }
  367. else
  368. {
  369. LOGMESSAGE1(_T("Error deleting value: %ld"), dwError);
  370. }
  371. }
  372. else
  373. {
  374. LOGMESSAGE2(_T("Couldn't open key %s: %ld"), pWinStationArray[i], dwError);
  375. }
  376. }
  377. }
  378. }
  379. return TRUE;
  380. }
  381. BOOL SubCompToggle::InformLicensingOfModeChange ()
  382. {
  383. BOOL fRet;
  384. ASSERT(StateObject.IsTSModeChanging());
  385. //
  386. // RPC into licensing to tell it we're going to reboot
  387. //
  388. HANDLE hServer = ServerLicensingOpen(NULL);
  389. if (NULL == hServer)
  390. {
  391. LOGMESSAGE1(_T("ERROR: InformLicensingOfModeChange calling ServerLicensingOpen <%lu>"), GetLastError());
  392. return FALSE;
  393. }
  394. fRet = ServerLicensingDeactivateCurrentPolicy(
  395. hServer
  396. );
  397. if (!fRet)
  398. {
  399. LOGMESSAGE1(_T("ERROR: InformLicensingOfModeChange calling ServerLicensingDeactivateCurrentPolicy <%lu>"), GetLastError());
  400. }
  401. ServerLicensingClose(hServer);
  402. return fRet;
  403. }
  404. BOOL SubCompToggle::SetPermissionsMode ()
  405. {
  406. //
  407. // If TS is toggling on, set the security key based on the choices
  408. // made through the wizard page. This must be done even if TS was
  409. // already enabled, as the permissions mode can be changed by the
  410. // unattended file.
  411. //
  412. CRegistry reg;
  413. EPermMode ePermMode = StateObject.CurrentPermMode();
  414. VERIFY(reg.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY) == ERROR_SUCCESS);
  415. // BUGBUG should be
  416. // return (ERROR_SUCCESS == reg.WriteRegDWord( _T("TSUserEnabled"), StateObject.IsItAppServer() ? (DWORD)ePermMode : (DWORD)PERM_WIN2K));
  417. return (ERROR_SUCCESS == reg.WriteRegDWord( _T("TSUserEnabled"), StateObject.IsTSEnableSelected() ? (DWORD)ePermMode : (DWORD)PERM_TS4));
  418. }
  419. BOOL RegisterDll(LPCTSTR szDll)
  420. {
  421. HMODULE hMod = LoadLibrary(szDll);
  422. HRESULT hResult = E_FAIL;
  423. if (hMod)
  424. {
  425. FARPROC pfRegSrv = GetProcAddress(hMod, "DllRegisterServer");
  426. if (pfRegSrv)
  427. {
  428. __try
  429. {
  430. hResult = (HRESULT)pfRegSrv();
  431. if (hResult != S_OK)
  432. {
  433. LOGMESSAGE2(_T("ERROR, DllRegister Server in %s failed, hResult = %x"), szDll, hResult);
  434. }
  435. }
  436. __except( 1 )
  437. {
  438. hResult = E_FAIL;
  439. LOGMESSAGE2(_T("ERROR, Exception hit Registrering of %s failed, Exception = %x"), szDll, GetExceptionCode());
  440. }
  441. }
  442. else
  443. {
  444. LOGMESSAGE1(_T("ERROR, Failed to Get proc for DllregisterServer for %s"), szDll);
  445. }
  446. FreeLibrary(hMod);
  447. }
  448. else
  449. {
  450. LOGMESSAGE2(_T("ERROR, Failed to Load library %s, lastError = %d"), szDll, GetLastError());
  451. }
  452. return hResult == S_OK;
  453. }
  454. BOOL SubCompToggle::ModifyWallPaperPolicy ()
  455. {
  456. BOOL bRet = FALSE;
  457. //
  458. // policy must be applied when we change modes.
  459. // also for fresh installs/upgrades of app server.
  460. //
  461. if (StateObject.IsAppSrvModeSwitch() || (StateObject.IsGuiModeSetup() && StateObject.IsItAppServer()))
  462. {
  463. LOGMESSAGE0(_T("Will apply/change policies now..."));
  464. if (StateObject.IsGuiModeSetup())
  465. {
  466. //
  467. // in case of Gui mode setup
  468. // the group policy object may not be registered yet.
  469. // so lets register it ourselves.
  470. //
  471. TCHAR szGPEditFile[MAX_PATH];
  472. if (GetSystemDirectory(szGPEditFile, MAX_PATH))
  473. {
  474. _tcscat(szGPEditFile, _T("\\gpedit.dll"));
  475. if (!RegisterDll(szGPEditFile))
  476. {
  477. LOGMESSAGE1(_T("Error, failed to register dll - %s."), szGPEditFile);
  478. }
  479. }
  480. else
  481. {
  482. LOGMESSAGE0(_T("Error, failed to GetSystemDirectory."));
  483. }
  484. }
  485. OleInitialize(NULL);
  486. IGroupPolicyObject *pIGroupPolicyObject = NULL;
  487. HRESULT hResult = CoCreateInstance(
  488. CLSID_GroupPolicyObject, //Class identifier (CLSID) of the object
  489. NULL, //Pointer to controlling IUnknown
  490. CLSCTX_ALL, //Context for running executable code
  491. IID_IGroupPolicyObject, //Reference to the identifier of the interface
  492. (void **)&pIGroupPolicyObject //Address of output variable that receives the interface pointer requested in riid
  493. );
  494. if (SUCCEEDED(hResult))
  495. {
  496. ASSERT(pIGroupPolicyObject);
  497. hResult = pIGroupPolicyObject->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
  498. if (SUCCEEDED(hResult))
  499. {
  500. HKEY hMachinePolicyKey = NULL;
  501. hResult = pIGroupPolicyObject->GetRegistryKey(GPO_SECTION_MACHINE, &hMachinePolicyKey);
  502. if (SUCCEEDED(hResult))
  503. {
  504. ASSERT(hMachinePolicyKey);
  505. const LPCTSTR szNoActiveDesktop_key = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer");
  506. const LPCTSTR szNoActiveDesktop_val = _T("NoActiveDesktop");
  507. const DWORD szNoActiveDesktop_dat = 1;
  508. CRegistry regMachinePolicy;
  509. if (ERROR_SUCCESS == regMachinePolicy.CreateKey(hMachinePolicyKey, szNoActiveDesktop_key))
  510. {
  511. if (StateObject.IsItAppServer())
  512. {
  513. if (ERROR_SUCCESS != regMachinePolicy.WriteRegDWord(szNoActiveDesktop_val, szNoActiveDesktop_dat))
  514. {
  515. LOGMESSAGE1(_T("ERROR, Failed to Write %s policy"), szNoActiveDesktop_val);
  516. }
  517. }
  518. else
  519. {
  520. if (ERROR_SUCCESS != regMachinePolicy.DeleteValue(szNoActiveDesktop_val))
  521. {
  522. LOGMESSAGE1(_T("Failed to delete %s policy"), szNoActiveDesktop_val);
  523. }
  524. }
  525. }
  526. pIGroupPolicyObject->Save(TRUE, TRUE, &guidRegistryEntension, &guidPolicyMachineSnapin);
  527. RegCloseKey(hMachinePolicyKey);
  528. bRet = TRUE;
  529. }
  530. else
  531. {
  532. LOGMESSAGE1(_T("ERROR, Failed to GetRegistryKey...hResult = %x"), hResult);
  533. }
  534. }
  535. else
  536. {
  537. LOGMESSAGE1(_T("ERROR, Failed to OpenLocalMachineGPO...hResult = %x"), hResult);
  538. }
  539. pIGroupPolicyObject->Release();
  540. }
  541. else
  542. {
  543. LOGMESSAGE1(_T("ERROR, Failed to get the interface IID_IGroupPolicyObject...hResult = %x"), hResult);
  544. }
  545. LOGMESSAGE0(_T("Done with Policy changes!"));
  546. }
  547. return bRet;
  548. }
  549. BOOL SubCompToggle::ModifyAppPriority()
  550. {
  551. if (StateObject.IsAppSrvModeSwitch())
  552. {
  553. DWORD dwSrvPrioity = StateObject.IsItAppServer() ? 0x26 : 0x18;
  554. LPCTSTR PRIORITY_KEY = _T("SYSTEM\\CurrentControlSet\\Control\\PriorityControl");
  555. CRegistry oReg;
  556. if (ERROR_SUCCESS == oReg.OpenKey(HKEY_LOCAL_MACHINE, PRIORITY_KEY))
  557. {
  558. if (ERROR_SUCCESS != oReg.WriteRegDWord(_T("Win32PrioritySeparation"), dwSrvPrioity))
  559. {
  560. LOGMESSAGE0(_T("Error, Failed to update Win32PrioritySeparation"));
  561. return FALSE;
  562. }
  563. return TRUE;
  564. }
  565. else
  566. {
  567. LOGMESSAGE1(_T("Errror, Failed to open %s key"), PRIORITY_KEY);
  568. return FALSE;
  569. }
  570. }
  571. return TRUE;
  572. }
  573. BOOL SubCompToggle::UpdateMMDefaults ()
  574. {
  575. LPCTSTR MM_REG_KEY = _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management");
  576. LPCTSTR SESSION_VIEW_SIZE_VALUE = _T("SessionViewSize");
  577. LPCTSTR SESSION_POOL_SIZE_VALUE = _T("SessionPoolSize");
  578. //
  579. // on app server machines, win32k uses the session pool, on all other platform
  580. // it uses the global pool. MM defaults (when these registry are not set) are
  581. // good only for TS AppServer.
  582. //
  583. // For all other platform we set new values for SessionPool (set to minumum allowed (4MB))
  584. // and higher value for SessionView.
  585. //
  586. const DWORD dwViewSizeforNonTS = 48;
  587. const DWORD dwPoolSizeforNonTS = 4;
  588. //
  589. // these default applies only for X86 machines
  590. //
  591. if (!StateObject.IsX86())
  592. return TRUE;
  593. CRegistry regMM;
  594. DWORD dwError = regMM.OpenKey(HKEY_LOCAL_MACHINE, MM_REG_KEY);
  595. if (ERROR_SUCCESS == dwError)
  596. {
  597. if (StateObject.IsItAppServer())
  598. {
  599. //
  600. // if this is a mode change then then we have to delete mm settings.
  601. //
  602. if (!StateObject.WasItAppServer())
  603. {
  604. //
  605. // for app server machines, MM defaults are good,
  606. //
  607. regMM.DeleteValue(SESSION_VIEW_SIZE_VALUE);
  608. regMM.DeleteValue(SESSION_POOL_SIZE_VALUE);
  609. }
  610. }
  611. else
  612. {
  613. //
  614. // for all other platform set SessionPool and SessionView.
  615. //
  616. dwError = regMM.WriteRegDWordNoOverWrite(SESSION_VIEW_SIZE_VALUE, dwViewSizeforNonTS);
  617. if (dwError != ERROR_SUCCESS)
  618. {
  619. LOGMESSAGE2(_T("ERROR, Failed to write %s for nonTS (%d)"), SESSION_VIEW_SIZE_VALUE, dwError);
  620. }
  621. dwError = regMM.WriteRegDWordNoOverWrite(SESSION_POOL_SIZE_VALUE, dwPoolSizeforNonTS);
  622. if (dwError != ERROR_SUCCESS)
  623. {
  624. LOGMESSAGE2(_T("ERROR, Failed to write %s for nonTS(%d)"), SESSION_POOL_SIZE_VALUE, dwError);
  625. }
  626. }
  627. }
  628. else
  629. {
  630. LOGMESSAGE1(_T("ERROR, Failed to open mm Key (%d)"), dwError);
  631. return FALSE;
  632. }
  633. return TRUE;
  634. }
  635. BOOL SubCompToggle::WriteModeSpecificRegistry ()
  636. {
  637. // here we do some registry changes that has weird requirements .
  638. // if the registry has to be retained on upgrades,
  639. // and it has different values for different modes then such registry
  640. // changes go here.
  641. if (!StateObject.IsServer())
  642. return true;
  643. CRegistry oRegTermsrv;
  644. DWORD dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  645. if (ERROR_SUCCESS == dwError)
  646. {
  647. DWORD dwSingleSessionPerUser;
  648. const TCHAR szSingleSession[] = _T("fSingleSessionPerUser");
  649. if (StateObject.IsItAppServer())
  650. {
  651. dwSingleSessionPerUser = 1;
  652. }
  653. else
  654. {
  655. dwSingleSessionPerUser = 0;
  656. }
  657. if (StateObject.IsAppSrvModeSwitch())
  658. {
  659. //
  660. // overwrite fSingleSessionPerUser with new value in case of mode switch.
  661. //
  662. dwError = oRegTermsrv.WriteRegDWord(szSingleSession, dwSingleSessionPerUser);
  663. }
  664. else
  665. {
  666. //
  667. // retain the original value in case of just upgrade.
  668. //
  669. dwError = oRegTermsrv.WriteRegDWordNoOverWrite(szSingleSession, dwSingleSessionPerUser);
  670. }
  671. if (ERROR_SUCCESS != dwError)
  672. {
  673. LOGMESSAGE1(_T("ERROR, failed to write fSingleSessionPerUser value(%d)"), dwError );
  674. }
  675. }
  676. else
  677. {
  678. LOGMESSAGE1(_T("ERROR, failed to open Termsrv registry(%d)"), dwError );
  679. }
  680. return ERROR_SUCCESS == dwError;
  681. }
  682. BOOL SubCompToggle::AddStartupPopup()
  683. {
  684. //
  685. // we need to popup a help checklist when a machine is turned into TS App Server.
  686. //
  687. if (!StateObject.CanShowStartupPopup())
  688. {
  689. LOGMESSAGE0(_T("CanShowStartupPopup returned false!"));
  690. return TRUE;
  691. }
  692. if (StateObject.IsItAppServer() && !StateObject.WasItAppServer())
  693. {
  694. CRegistry oReg;
  695. DWORD dwError = oReg.OpenKey(HKEY_LOCAL_MACHINE, RUN_KEY);
  696. if (dwError == ERROR_SUCCESS)
  697. {
  698. dwError = oReg.WriteRegExpString(HELP_POPUPRUN_VALUE, HELP_PUPUP_COMMAND);
  699. if (dwError != ERROR_SUCCESS)
  700. {
  701. LOGMESSAGE1(_T("Error Failed to write Runonce value"), dwError);
  702. }
  703. else
  704. {
  705. LOGMESSAGE0(_T("added the startup Checklist Link!"));
  706. }
  707. }
  708. else
  709. {
  710. LOGMESSAGE1(_T("Error Failed to open Runonce key"), dwError);
  711. }
  712. }
  713. return TRUE;
  714. }
  715. #pragma warning(pop)