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.

325 lines
9.8 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1997 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. startup.c
  7. Abstract:
  8. Implements the Startup/Recovery dialog of the System
  9. Control Panel Applet
  10. Author:
  11. Eric Flo (ericflo) 19-Jun-1995
  12. Revision History:
  13. 15-Oct-1997 scotthal
  14. Complete overhaul
  15. --*/
  16. #include <sysdm.h>
  17. #ifdef _X86_
  18. extern TCHAR szBootIni[];
  19. #endif
  20. //
  21. // Globals for this dialog
  22. //
  23. #define CSEC_START_MAX 9999 // Maximum number of seconds allowed
  24. BOOL g_fStartupInitializing;
  25. BOOL g_fRebootRequired = FALSE;
  26. #if defined(_X86_) || defined(EFI_NVRAM_ENABLED)
  27. BOOL g_fSystemStartupEnabled = TRUE;
  28. #else
  29. BOOL g_fSystemStartupEnabled = FALSE;
  30. #endif
  31. //
  32. // Help ID's
  33. //
  34. DWORD aStartupHelpIds[] = {
  35. IDC_STARTUP_SYS_OS_LABEL, (IDH_STARTUP + 0),
  36. IDC_STARTUP_SYS_OS, (IDH_STARTUP + 0),
  37. IDC_STARTUP_SYS_ENABLECOUNTDOWN, (IDH_STARTUP + 1),
  38. IDC_STARTUP_SYS_SECONDS, (IDH_STARTUP + 2),
  39. IDC_STARTUP_SYS_SECONDS_LABEL, (IDH_STARTUP + 2),
  40. IDC_STARTUP_CDMP_TXT1, (IDH_STARTUP + 3),
  41. IDC_STARTUP_CDMP_LOG, (IDH_STARTUP + 4),
  42. IDC_STARTUP_CDMP_SEND, (IDH_STARTUP + 5),
  43. IDC_STARTUP_CDMP_FILENAME, (IDH_STARTUP + 7),
  44. IDC_STARTUP_CDMP_OVERWRITE, (IDH_STARTUP + 13),
  45. IDC_STARTUP_CDMP_AUTOREBOOT, (IDH_STARTUP + 9),
  46. IDC_STARTUP_SYSTEM_GRP, (IDH_STARTUP + 10),
  47. IDC_STARTUP_SYS_SECSCROLL, (IDH_STARTUP + 11),
  48. IDC_STARTUP_CDMP_GRP, (IDH_STARTUP + 12),
  49. IDC_STARTUP_CDMP_DEBUGINFO_GROUP, (IDH_STARTUP + 14),
  50. IDC_STARTUP_CDMP_TYPE, (IDH_STARTUP + 8),
  51. IDC_STARTUP_CDMP_FILE_LABEL, (IDH_STARTUP + 7),
  52. IDC_STARTUP_SYS_EDIT_LABEL, (IDH_STARTUP + 15),
  53. IDC_SYS_EDIT_BUTTION, (IDH_STARTUP + 16),
  54. 0, 0
  55. };
  56. INT_PTR
  57. APIENTRY
  58. StartupDlgProc(
  59. IN HWND hDlg,
  60. IN UINT uMsg,
  61. IN WPARAM wParam,
  62. IN LPARAM lParam
  63. )
  64. /*++
  65. Routine Description:
  66. Handles messages sent to the Startup/Recovery dialog box
  67. Arguments:
  68. hDlg -
  69. Supplies window handle
  70. uMsg -
  71. Supplies message being sent
  72. wParam -
  73. Supplies message parameter
  74. lParam -
  75. Supplies message parameter
  76. Return Value:
  77. TRUE if message was handled
  78. FALSE if message was unhandled
  79. --*/
  80. {
  81. int iRet;
  82. // If any controls on this page are touched by the user,
  83. // enable the "Apply" button.
  84. if ((WM_COMMAND == uMsg) && (!g_fStartupInitializing)) {
  85. switch (HIWORD(wParam)) {
  86. case EN_CHANGE:
  87. case BN_CLICKED:
  88. case CBN_SELCHANGE:
  89. PropSheet_Changed(GetParent(hDlg), hDlg);
  90. break;
  91. default:
  92. break;
  93. } // switch (HIWORD(wParam))
  94. } // if ((WM_COMMAND...
  95. // Call the Core Dump stuff first. Only handle
  96. // messages not handled by the Core Dump stuff.
  97. iRet = CoreDumpDlgProc(hDlg, uMsg, wParam, lParam);
  98. switch( iRet ) {
  99. case RET_CONTINUE: {
  100. break;
  101. }
  102. case RET_BREAK: {
  103. return TRUE;
  104. }
  105. case RET_ERROR: {
  106. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  107. return TRUE;
  108. }
  109. case RET_CHANGE_NO_REBOOT:
  110. case RET_NO_CHANGE: {
  111. break;
  112. }
  113. case RET_VIRTUAL_CHANGE:
  114. case RET_RECOVER_CHANGE:
  115. case RET_VIRT_AND_RECOVER: {
  116. g_fRebootRequired = TRUE;
  117. MsgBoxParam(
  118. hDlg,
  119. IDS_SYSDM_RESTART,
  120. IDS_SYSDM_TITLE,
  121. MB_OK | MB_ICONINFORMATION
  122. );
  123. break;
  124. }
  125. }
  126. switch (uMsg)
  127. {
  128. case WM_INITDIALOG:
  129. g_fStartupInitializing = TRUE;
  130. StartListInit(hDlg, wParam, lParam);
  131. AutoAdvancedBootInit(hDlg, wParam, lParam);
  132. g_fStartupInitializing = FALSE;
  133. if (!IsUserAnAdmin())
  134. {
  135. EnableWindow(GetDlgItem(hDlg, IDC_SYS_EDIT_BUTTION), FALSE);
  136. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_EDIT_LABEL), FALSE);
  137. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_AUTOLKG), FALSE);
  138. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_AUTOLKG_SECONDS_LABEL), FALSE);
  139. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_AUTOLKG_SECONDS), FALSE);
  140. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_AUTOLKG_SECSCROLL), FALSE);
  141. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_CDMP_FILE_LABEL), FALSE);
  142. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_CDMP_FILENAME), FALSE);
  143. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_CDMP_OVERWRITE), FALSE);
  144. }
  145. if (!g_fSystemStartupEnabled || !IsUserAnAdmin())
  146. {
  147. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYSTEM_GRP), FALSE);
  148. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_OS), FALSE);
  149. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_OS_LABEL), FALSE);
  150. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_ENABLECOUNTDOWN), FALSE);
  151. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_SECONDS_LABEL), FALSE);
  152. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_SECONDS), FALSE);
  153. EnableWindow(GetDlgItem(hDlg, IDC_STARTUP_SYS_EDIT_LABEL), FALSE);
  154. EnableWindow(GetDlgItem(hDlg, IDC_SYS_EDIT_BUTTION), FALSE);
  155. }
  156. break;
  157. case WM_COMMAND:
  158. switch (LOWORD(wParam)) {
  159. case IDC_STARTUP_AUTOLKG:
  160. if (HIWORD(wParam) == BN_CLICKED) {
  161. BOOL fEnabled;
  162. fEnabled = !IsDlgButtonChecked(hDlg, IDC_STARTUP_AUTOLKG);
  163. CheckDlgButton(hDlg, IDC_STARTUP_AUTOLKG, fEnabled);
  164. EnableWindow(GetDlgItem (hDlg, IDC_STARTUP_AUTOLKG_SECONDS), fEnabled);
  165. EnableWindow(GetDlgItem (hDlg, IDC_STARTUP_AUTOLKG_SECSCROLL), fEnabled);
  166. }
  167. break;
  168. case IDC_STARTUP_SYS_ENABLECOUNTDOWN:
  169. if (HIWORD(wParam) == BN_CLICKED) {
  170. int timeout;
  171. timeout = IsDlgButtonChecked(hDlg, IDC_STARTUP_SYS_ENABLECOUNTDOWN) ? 0 : 30;
  172. CheckDlgButton(hDlg, IDC_STARTUP_SYS_ENABLECOUNTDOWN,
  173. (BOOL) timeout);
  174. SetDlgItemInt(hDlg, IDC_STARTUP_SYS_SECONDS, timeout, FALSE);
  175. EnableWindow(GetDlgItem (hDlg, IDC_STARTUP_SYS_SECONDS), (BOOL) timeout);
  176. EnableWindow(GetDlgItem (hDlg, IDC_STARTUP_SYS_SECSCROLL), (BOOL) timeout);
  177. }
  178. break;
  179. case IDOK: {
  180. int r1, r2;
  181. if((RET_BREAK != StartListExit(hDlg, wParam, lParam)) &&
  182. (RET_BREAK != AutoAdvancedBootExit(hDlg, wParam, lParam)))
  183. {
  184. EndDialog(hDlg, 0);
  185. } // if
  186. break;
  187. }
  188. case IDCANCEL:
  189. AutoAdvancedBootExit(hDlg, wParam, lParam);
  190. EndDialog(hDlg, 0);
  191. break;
  192. case IDC_STARTUP_SYS_SECONDS:
  193. if (HIWORD(wParam) == EN_UPDATE) {
  194. if (!CheckVal(hDlg, IDC_STARTUP_SYS_SECONDS, FORMIN, FORMAX, IDS_SYSDM_ENTERSECONDS)) {
  195. SetDlgItemInt(hDlg, IDC_STARTUP_SYS_SECONDS, FORDEF, FALSE);
  196. SendMessage((HWND) lParam, EM_SETSEL, 0, -1);
  197. } // if (!CheckVal(...
  198. } // if (HIWORD(wParam == EN_UPDATE)
  199. break;
  200. case IDC_STARTUP_AUTOLKG_SECONDS:
  201. if (HIWORD(wParam) == EN_UPDATE)
  202. {
  203. if (!CheckVal(hDlg, IDC_STARTUP_AUTOLKG_SECONDS, 0, 200, IDS_SYSDM_ENTERSECONDS))
  204. {
  205. SetDlgItemInt(hDlg, IDC_STARTUP_AUTOLKG_SECONDS, 30, FALSE);
  206. SendMessage((HWND) lParam, EM_SETSEL, 0, -1);
  207. } // if (!CheckVal(...
  208. } // if (HIWORD(wParam == EN_UPDATE)
  209. break;
  210. case IDC_SYS_EDIT_BUTTION:
  211. {
  212. // invoke notepad.exe to edit boot.ini file
  213. DWORD dwFileAttr;
  214. SHELLEXECUTEINFO ExecInfo = {0};
  215. #ifdef _X86_
  216. ExecInfo.lpParameters = szBootIni;
  217. #else
  218. ExecInfo.lpParameters = TEXT("c:\\boot.ini");
  219. #endif // _X86_
  220. ExecInfo.lpFile = TEXT("%windir%\\system32\\NOTEPAD.EXE");
  221. ExecInfo.fMask = SEE_MASK_DOENVSUBST;
  222. ExecInfo.nShow = SW_SHOWNORMAL;
  223. ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  224. // Change Read-only file attrs on Boot.ini file if necessary
  225. if ((dwFileAttr = GetFileAttributes (ExecInfo.lpParameters)) != 0xFFFFFFFF)
  226. {
  227. if (dwFileAttr & FILE_ATTRIBUTE_READONLY)
  228. {
  229. SetFileAttributes (ExecInfo.lpParameters, dwFileAttr & ~FILE_ATTRIBUTE_READONLY);
  230. }
  231. }
  232. ShellExecuteEx(&ExecInfo);
  233. }
  234. break;
  235. } // switch (LOWORD(wParam))
  236. break;
  237. case WM_DESTROY:
  238. StartListDestroy(hDlg, wParam, lParam);
  239. break;
  240. case WM_HELP: // F1
  241. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  242. (DWORD_PTR) (LPSTR) aStartupHelpIds);
  243. break;
  244. case WM_CONTEXTMENU: // right mouse click
  245. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  246. (DWORD_PTR) (LPSTR) aStartupHelpIds);
  247. break;
  248. default:
  249. return FALSE;
  250. }
  251. return TRUE;
  252. }