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.

315 lines
7.1 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation
  2. //
  3. // File: cys.cpp
  4. //
  5. // Synopsis: Configure Your Server Wizard main
  6. //
  7. // History: 02/02/2001 JeffJon Created
  8. #include "pch.h"
  9. #include "resource.h"
  10. #include "state.h"
  11. #include "InstallationUnitProvider.h"
  12. // include the wizard pages
  13. #include "WelcomePage.h"
  14. #include "BeforeBeginPage.h"
  15. #include "DecisionPage.h"
  16. #include "NICSelectionPage.h"
  17. #include "DomainPage.h"
  18. #include "NetbiosPage.h"
  19. #include "RestorePasswordPage.h"
  20. #include "ExpressDNSPage.h"
  21. #include "ExpressDHCPPage.h"
  22. #include "CustomServerPage.h"
  23. #include "ClusterPage.h"
  24. #include "NetworkServerPage.h"
  25. #include "PrintServerPage.h"
  26. #include "TerminalServerPage.h"
  27. #include "SharePointPage.h"
  28. #include "FileServerPage.h"
  29. #include "IndexingPage.h"
  30. #include "FinishPage.h"
  31. HINSTANCE hResourceModuleHandle = 0;
  32. const wchar_t* HELPFILE_NAME = 0; // no context help available
  33. // This is the name of a mutex that is used to see if CYS is running
  34. const wchar_t* RUNTIME_NAME = L"cysui";
  35. DWORD DEFAULT_LOGGING_OPTIONS =
  36. Log::OUTPUT_TO_FILE
  37. | Log::OUTPUT_FUNCCALLS
  38. | Log::OUTPUT_LOGS
  39. | Log::OUTPUT_ERRORS
  40. | Log::OUTPUT_HEADER
  41. | Log::OUTPUT_RUN_TIME;
  42. // a system modal popup thingy
  43. Popup popup(IDS_WIZARD_TITLE, true);
  44. // this is the mutex that indicates that CYS is running.
  45. HANDLE cysRunningMutex = INVALID_HANDLE_VALUE;
  46. // these are the valid exit codes returned from the cys.exe process
  47. enum ExitCode
  48. {
  49. // the operation failed.
  50. EXIT_CODE_UNSUCCESSFUL = 0,
  51. // the operation succeeded
  52. EXIT_CODE_SUCCESSFUL = 1,
  53. // other exit codes can be added here...
  54. };
  55. ExitCode
  56. RunWizard()
  57. {
  58. LOG_FUNCTION(RunWizard);
  59. ExitCode exitCode = EXIT_CODE_SUCCESSFUL;
  60. // Create the wizard and add all the pages
  61. Wizard wiz(
  62. IDS_WIZARD_TITLE,
  63. IDB_BANNER16,
  64. IDB_BANNER256,
  65. IDB_WATERMARK16,
  66. IDB_WATERMARK256);
  67. wiz.AddPage(new WelcomePage());
  68. wiz.AddPage(new BeforeBeginPage());
  69. wiz.AddPage(new DecisionPage());
  70. wiz.AddPage(new NICSelectionPage());
  71. wiz.AddPage(new ADDomainPage());
  72. wiz.AddPage(new NetbiosDomainPage());
  73. wiz.AddPage(new RestorePasswordPage());
  74. wiz.AddPage(new ExpressDNSPage());
  75. wiz.AddPage(new ExpressDHCPPage());
  76. wiz.AddPage(new CustomServerPage());
  77. wiz.AddPage(new ClusterPage());
  78. wiz.AddPage(new NetworkServerPage());
  79. wiz.AddPage(new PrintServerPage());
  80. wiz.AddPage(new TerminalServerPage());
  81. wiz.AddPage(new SharePointPage());
  82. wiz.AddPage(new FileServerPage());
  83. wiz.AddPage(new IndexingPage());
  84. wiz.AddPage(new FinishPage());
  85. // Run the wizard
  86. switch (wiz.ModalExecute())
  87. {
  88. case -1:
  89. {
  90. /* popup.Error(
  91. Win::GetDesktopWindow(),
  92. E_FAIL,
  93. IDS_PROP_SHEET_FAILED);
  94. */
  95. exitCode = EXIT_CODE_UNSUCCESSFUL;
  96. break;
  97. }
  98. case ID_PSREBOOTSYSTEM:
  99. {
  100. // we can infer that if we are supposed to reboot, then the
  101. // operation was successful.
  102. exitCode = EXIT_CODE_SUCCESSFUL;
  103. break;
  104. }
  105. default:
  106. {
  107. // do nothing.
  108. break;
  109. }
  110. }
  111. return exitCode;
  112. }
  113. ExitCode
  114. Start()
  115. {
  116. LOG_FUNCTION(Start);
  117. ExitCode exitCode = EXIT_CODE_UNSUCCESSFUL;
  118. do
  119. {
  120. // Put any checks that should stop the wizard from running here...
  121. // User must be an Administrator
  122. bool isAdmin = ::IsCurrentUserAdministrator();
  123. if (!isAdmin)
  124. {
  125. LOG(L"Current user is not an Administrator");
  126. popup.MessageBox(
  127. Win::GetDesktopWindow(),
  128. IDS_NOT_ADMIN,
  129. MB_OK);
  130. State::GetInstance().SetRerunWizard(false);
  131. exitCode = EXIT_CODE_UNSUCCESSFUL;
  132. break;
  133. }
  134. // Machine cannot be in the middle of a DC upgrade
  135. if (State::GetInstance().IsUpgradeState())
  136. {
  137. LOG(L"Machine needs to complete DC upgrade");
  138. String commandline = Win::GetCommandLine();
  139. // If we were launched from explorer then
  140. // don't show the message, just exit silently
  141. if (commandline.find(EXPLORER_SWITCH) == String::npos)
  142. {
  143. popup.MessageBox(
  144. Win::GetDesktopWindow(),
  145. IDS_DC_UPGRADE_NOT_COMPLETE,
  146. MB_OK);
  147. }
  148. State::GetInstance().SetRerunWizard(false);
  149. exitCode = EXIT_CODE_UNSUCCESSFUL;
  150. break;
  151. }
  152. // Machine cannot have DCPROMO running or a reboot pending
  153. if (State::GetInstance().IsDCPromoRunning())
  154. {
  155. LOG(L"DCPROMO is running");
  156. popup.MessageBox(
  157. Win::GetDesktopWindow(),
  158. IDS_DCPROMO_RUNNING,
  159. MB_OK);
  160. State::GetInstance().SetRerunWizard(false);
  161. exitCode = EXIT_CODE_UNSUCCESSFUL;
  162. break;
  163. }
  164. else if (State::GetInstance().IsDCPromoPendingReboot())
  165. {
  166. LOG(L"DCPROMO was run, pending reboot");
  167. popup.MessageBox(
  168. Win::GetDesktopWindow(),
  169. IDS_DCPROMO_PENDING_REBOOT,
  170. MB_OK);
  171. State::GetInstance().SetRerunWizard(false);
  172. exitCode = EXIT_CODE_UNSUCCESSFUL;
  173. break;
  174. }
  175. // We can run the wizard. Yea!!!
  176. exitCode = RunWizard();
  177. }
  178. while (0);
  179. LOG(String::format(L"exitCode = %1!d!", static_cast<int>(exitCode)));
  180. return exitCode;
  181. }
  182. int WINAPI
  183. WinMain(
  184. HINSTANCE hInstance,
  185. HINSTANCE /* hPrevInstance */ ,
  186. PSTR /* lpszCmdLine */ ,
  187. int /* nCmdShow */)
  188. {
  189. hResourceModuleHandle = hInstance;
  190. ExitCode exitCode = EXIT_CODE_UNSUCCESSFUL;
  191. HRESULT hr = Win::CreateMutex(0, true, RUNTIME_NAME, cysRunningMutex);
  192. if (hr == Win32ToHresult(ERROR_ALREADY_EXISTS))
  193. {
  194. popup.MessageBox(
  195. Win::GetDesktopWindow(),
  196. IDS_ALREADY_RUNNING,
  197. MB_OK);
  198. }
  199. else
  200. {
  201. do
  202. {
  203. hr = ::CoInitialize(0);
  204. if (FAILED(hr))
  205. {
  206. ASSERT(SUCCEEDED(hr));
  207. break;
  208. }
  209. /* Keep this around. It may be useful in the future when we are
  210. determining the network settings
  211. INITCOMMONCONTROLSEX sex;
  212. sex.dwSize = sizeof(sex);
  213. sex.dwICC = ICC_ANIMATE_CLASS | ICC_USEREX_CLASSES;
  214. BOOL init = ::InitCommonControlsEx(&sex);
  215. ASSERT(init);
  216. */
  217. // Register the Link Window class
  218. LinkWindow_RegisterClass();
  219. do
  220. {
  221. exitCode = Start();
  222. } while(State::GetInstance().RerunWizard());
  223. // Set the regkey to not run again
  224. String emptyString;
  225. bool result = SetRegKeyValue(
  226. CYS_HOME_REGKEY,
  227. emptyString,
  228. CYS_HOME_RUN_KEY_DONT_RUN,
  229. HKEY_CURRENT_USER,
  230. true);
  231. ASSERT(result);
  232. // Perform cleanup
  233. InstallationUnitProvider::Destroy();
  234. State::Destroy();
  235. // Unregister the Link Window class
  236. LinkWindow_UnregisterClass(hResourceModuleHandle);
  237. } while(false);
  238. }
  239. return static_cast<int>(exitCode);
  240. }