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.

558 lines
19 KiB

  1. /****************************************************************************
  2. PROGRAM: getmttf.c
  3. AUTHOR: Lars Opstad (LarsOp) 3/18/93
  4. PURPOSE: Setup for NT Mean-time-to-failure reporting tool.
  5. FUNCTIONS:
  6. WinMain() - parse command line and starts each dialog box
  7. FrameWndProc() - processes messages
  8. About() - processes messages for "About" dialog box
  9. COMMENTS:
  10. This program displays 2 dialog boxes to prompt the user for
  11. who he/she is and what tests to run. It then starts tests
  12. (in INIIO.c) and registers with a server (in CLIENT.c).
  13. ****************************************************************************/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include "setup.h" /* specific to this program */
  18. #define IniFileName "Mttf.ini"
  19. #define MTTFEXE "Mttf.exe"
  20. #define MTTFVWR "Mttfvwr.exe"
  21. #ifdef MIPS
  22. #define DEFAULT_PATH "a:\\"
  23. #else
  24. #define DEFAULT_PATH "a:\\"
  25. #endif
  26. #define DEFAULT_MTTF_FILE "\\\\server\\share\\mttf.dat"
  27. #define DEFAULT_NAMES_FILE "\\\\server\\share\\names.dat"
  28. #define DEFAULT_IDLE_LIMIT 10
  29. #define DEFAULT_386_IDLE_LIMIT 15
  30. #define DEFAULT_POLLING_PERIOD 15
  31. #define MAX_POLLING_PERIOD 60
  32. HANDLE hInst; // current instance
  33. DWORD PollingPeriod;
  34. DWORD IdlePercentage;
  35. char SetupDir[MAX_DIR];
  36. char ResultsFile[MAX_DIR],NameFile[MAX_DIR];
  37. char Path[MAX_DIR];
  38. char SysDir[MAX_DIR],
  39. Buf1[MAX_DIR],
  40. Buf2[MAX_DIR];
  41. /****************************************************************************
  42. FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  43. PURPOSE: Checks command args then displays dialogs
  44. COMMENTS:
  45. Parse the command arguments.
  46. If the user hasn't specified name, office and dir,
  47. display signon dialog.
  48. Display test selection dialog.
  49. ****************************************************************************/
  50. int WINAPI
  51. WinMain(
  52. HINSTANCE hInstance,
  53. HINSTANCE hPrevInstance,
  54. LPSTR lpCmdLine,
  55. int nCmdShow
  56. )
  57. {
  58. SYSTEM_INFO sysinfo;
  59. char Buffer[MAX_DIR],
  60. WinDir[MAX_DIR],
  61. *EndOfPath;
  62. INT_PTR dlgRet=FALSE;
  63. CMO cmo=cmoVital;
  64. hInst = hInstance;
  65. //
  66. // Get directory EXE was run from.
  67. //
  68. GetModuleFileName(NULL, SetupDir, sizeof(SetupDir));
  69. //
  70. // Strip off exe name to use as default dir to get files from.
  71. // Might be a:\, b:\ or \\srv\share\
  72. //
  73. _strlwr(SetupDir);
  74. if (EndOfPath=strstr(SetupDir,"getmttf.exe")) {
  75. *EndOfPath=0;
  76. }
  77. FInitProgManDde(hInst);
  78. GetSystemInfo(&sysinfo); // Get system info
  79. //
  80. // if the processortype is 386, set idle percent to 386 limit.
  81. //
  82. if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL &&
  83. sysinfo.wProcessorLevel < 4
  84. ) {
  85. IdlePercentage = DEFAULT_386_IDLE_LIMIT;
  86. } else {
  87. IdlePercentage = DEFAULT_IDLE_LIMIT;
  88. }
  89. GetSystemDirectory(SysDir, MAX_DIR);
  90. //
  91. // Try to copy the EXEs
  92. //
  93. MakeFileName(Buf1, SetupDir,MTTFEXE);
  94. MakeFileName(Buf2, SysDir, MTTFEXE);
  95. if (CopyFile(Buf1, Buf2, FALSE)) {
  96. MakeFileName(Buf1, SetupDir, MTTFVWR);
  97. MakeFileName(Buf2, SysDir, MTTFVWR);
  98. if (CopyFile(Buf1, Buf2, FALSE)) {
  99. MakeFileName(Buf1, SetupDir, IniFileName);
  100. ReadIniFile(Buf1);
  101. dlgRet=TRUE; // If both EXEs copy, set flag to not show signon
  102. }
  103. }
  104. //
  105. // Only display the dialog if one of the EXEs didn't copy from default dir.
  106. //
  107. if (!dlgRet) {
  108. //
  109. // Display signon dlg
  110. //
  111. dlgRet = DialogBox(hInstance, (LPCSTR)IDD_SIGNON, NULL, SignonDlgProc);
  112. }
  113. if (dlgRet) {
  114. //
  115. // Display test selection dialog
  116. //
  117. dlgRet = DialogBox(hInstance, (LPCSTR)IDD_VALUES, NULL, ValuesDlgProc);
  118. if (!dlgRet) {
  119. goto AbortApp;
  120. }
  121. GetWindowsDirectory(WinDir, MAX_DIR);
  122. MakeFileName(Buffer, WinDir, IniFileName);
  123. WriteIniFile(Buffer);
  124. FCreateProgManGroup("Startup", "", cmo, TRUE);
  125. FCreateProgManItem("Startup", "Mttf", "Mttf.Exe", "", 0, cmo, FALSE);
  126. if (ResultsFile[0]) {
  127. sprintf(Buffer, "cmd /k Mttfvwr %s", ResultsFile);
  128. } else {
  129. sprintf(Buffer, "cmd /k mttfvwr c:\\mttf.ini");
  130. }
  131. FCreateProgManGroup("Main", "", cmo, FALSE);
  132. FCreateProgManItem("Main", "Mttf Viewer", Buffer, "", 0, cmo, FALSE);
  133. MessageBox(NULL,
  134. "If you are not an Administrator and often log on to this "
  135. "machine with a different username, please add mttf.exe to "
  136. "the startup group for each user.\n\n"
  137. "The following are the keys to valid mttf numbers:\n\n"
  138. "1. Answer prompts correctly for warm/cold boot problems\n"
  139. "2. Report \"Other\" problems by double-clicking the app\n"
  140. "3. Disable while performing unusual tests (such as stress)\n"
  141. "4. Install Mttf as soon as possible after upgrading.\n\n"
  142. "Setup is now complete. Please go to ProgMan and start Mttf.",
  143. "Mttf Setup Complete",
  144. MB_OK|MB_ICONINFORMATION);
  145. } else {
  146. AbortApp:
  147. MessageBox(NULL,
  148. "Mttf setup did NOT install correctly. Please rerun setup.",
  149. "Mttf Setup Failed",
  150. MB_OK|MB_ICONHAND);
  151. }
  152. return 0;
  153. } // WinMain()
  154. VOID
  155. WriteIniFile (
  156. char *filename
  157. )
  158. {
  159. char Buffer[MAX_DIR];
  160. WritePrivateProfileString("Mttf", "ResultsFile", ResultsFile, filename);
  161. WritePrivateProfileString("Mttf", "NameFile", NameFile, filename);
  162. sprintf(Buffer, "%ld", PollingPeriod);
  163. WritePrivateProfileString("Mttf", "PollingPeriod", Buffer, filename);
  164. sprintf(Buffer, "%ld", IdlePercentage);
  165. WritePrivateProfileString("Mttf", "IdlePercent", Buffer, filename);
  166. }
  167. VOID
  168. ReadIniFile (
  169. char *filename
  170. )
  171. {
  172. GetPrivateProfileString("Mttf",
  173. "NameFile",
  174. DEFAULT_NAMES_FILE,
  175. NameFile,
  176. MAX_DIR,
  177. filename);
  178. GetPrivateProfileString("Mttf",
  179. "ResultsFile",
  180. DEFAULT_MTTF_FILE,
  181. ResultsFile,
  182. MAX_DIR,
  183. filename);
  184. PollingPeriod = GetPrivateProfileInt("Mttf",
  185. "PollingPeriod",
  186. DEFAULT_POLLING_PERIOD,
  187. filename);
  188. IdlePercentage = GetPrivateProfileInt("Mttf",
  189. "IdlePercent",
  190. IdlePercentage,
  191. filename);
  192. }
  193. VOID
  194. MakeFileName (
  195. char *DestBuffer,
  196. char *Path,
  197. char *FileName
  198. )
  199. {
  200. DWORD len;
  201. char ch;
  202. len=strlen(Path);
  203. ch=(len?Path[len-1]:':');
  204. switch (ch) {
  205. case ':':
  206. case '\\':
  207. sprintf(DestBuffer, "%s%s", Path, FileName);
  208. break;
  209. default:
  210. sprintf(DestBuffer, "%s\\%s", Path, FileName);
  211. }
  212. }
  213. /****************************************************************************
  214. FUNCTION: SignonDlgProc(HWND, UINT, UINT, UINT)
  215. PURPOSE: Dialog procedure for signon dialog.
  216. COMMENTS: The signon dialog gets important information for locating
  217. machine and owner when tracking down problems.
  218. WM_INITDIALOG: Set default values and focus for input variables
  219. WM_COMMAND: Process the button press:
  220. IDOK: Get input values and check for validity.
  221. IDCANCEL: Kill the app.
  222. IDB_HELP: Descriptive message box
  223. ****************************************************************************/
  224. INT_PTR
  225. SignonDlgProc(
  226. HWND hDlg,
  227. UINT message,
  228. WPARAM wParam,
  229. LPARAM lParam
  230. )
  231. {
  232. switch (message)
  233. {
  234. case WM_INITDIALOG: // initialize values and focus
  235. SetDlgItemText(hDlg, IDS_PATH, SetupDir);
  236. return (TRUE);
  237. case WM_COMMAND: // command: button pressed
  238. switch (wParam) // which button
  239. {
  240. //
  241. // OK: Get and check the input values and try to copy exes
  242. //
  243. case IDOK:
  244. GetDlgItemText(hDlg, IDS_PATH, Path, MAX_DIR);
  245. MakeFileName(Buf1,Path,MTTFEXE);
  246. MakeFileName(Buf2,SysDir, MTTFEXE);
  247. if (!CopyFile(Buf1, Buf2, FALSE)) {
  248. sprintf(Buf1, "Error copying %s from %s to %s (%ld). Please reenter source path.",
  249. MTTFEXE, Path, SysDir, GetLastError());
  250. MessageBox(NULL,
  251. Buf1,
  252. "Error Copying",
  253. MB_OK|MB_ICONHAND);
  254. return (FALSE);
  255. }
  256. MakeFileName(Buf1, Path, MTTFVWR);
  257. MakeFileName(Buf2, SysDir, MTTFVWR);
  258. if (!CopyFile(Buf1, Buf2, FALSE)) {
  259. sprintf(Buf1, "Error copying %s from %s to %s (%ld). Please reenter source path.",
  260. MTTFVWR, Path, SysDir, GetLastError());
  261. if (IDRETRY==MessageBox(NULL,
  262. Buf1,
  263. "Error Copying",
  264. MB_RETRYCANCEL|MB_ICONHAND)) {
  265. return (FALSE);
  266. }
  267. }
  268. MakeFileName(Buf1,Path,IniFileName);
  269. ReadIniFile(Buf1);
  270. EndDialog(hDlg, TRUE);
  271. return (TRUE);
  272. case IDCANCEL:
  273. EndDialog(hDlg, FALSE);
  274. return (TRUE);
  275. //
  276. // HELP: Descriptive message box (.HLP file would be overkill)
  277. //
  278. case IDB_HELP:
  279. MessageBox( NULL,
  280. "Mttf tracks the amount of time your machine stays up, "
  281. "the number of cold and warm boots, and "
  282. "the number of other problems that occur on your machine. "
  283. "All this information is written to a server that is "
  284. "specified in mttf.ini (in your Windows NT directory).\n\n"
  285. "This part of setup requests the path to the distribution "
  286. "files for Mttf. This may be a:\\, a server (\\\\srv\\shr) or "
  287. "any other valid specification. If Mttf.exe can not be "
  288. "copied, setup reprompts for a path. If MttfVwr.exe can "
  289. "not be copied, a warning is displayed that can be ignored "
  290. "or retried.",
  291. "Mean Time to Failure Setup Help",
  292. MB_OK
  293. );
  294. return (TRUE);
  295. default:
  296. break;
  297. } // switch (wParam)
  298. break;
  299. default:
  300. break;
  301. } // switch (message)
  302. return (FALSE); // Didn't process a message
  303. } // SignonDlgProc()
  304. /****************************************************************************
  305. FUNCTION: ValuesDlgProc(HWND, UINT, UINT, UINT)
  306. PURPOSE: Dialog procedure for test selection dialog.
  307. COMMENTS: Test selection dialog allows user to add and remove tests
  308. before and after starting stress.
  309. WM_INITDIALOG: Set default values and focus for input variables
  310. WM_CLOSE...: Send Shutdown message to server for any legal shutdown
  311. WM_COMMAND: Process the button/listbox press:
  312. IDOK: Get input values and check for validity.
  313. IDCANCEL: Kill the app.
  314. IDB_HELP: Descriptive message box
  315. IDT_SAVE: Prompt for groupname and save selection to ini file
  316. IDT_ADD: Add highlighted tests to selected list (remove from poss)
  317. IDT_REMOVE:Remove highlighted tests from selected list (add to poss)
  318. IDT_LABEL...: For labels, set selection to corresponding list/combo
  319. IDT_SEL: Perform operation depending on action on selected listbox
  320. LBN_SELCHANGE: Activate Remove button and clear Poss highlights
  321. LBN_DBLCLK: Get number of instances for the selected test
  322. IDT_POSS: Perform operation depending on action on possible listbox
  323. LBN_SELCHANGE: Activate Add button and clear selected highlights
  324. LBN_DBLCLK: Add highlighted test (simulate press to Add button)
  325. IDT_GROUP: Change to new group.
  326. ****************************************************************************/
  327. INT_PTR
  328. ValuesDlgProc(
  329. HWND hDlg,
  330. UINT message,
  331. WPARAM wParam,
  332. LPARAM lParam
  333. )
  334. {
  335. static DWORD defPP;
  336. BOOL Translated;
  337. CHAR Buffer[MAX_DIR];
  338. HFILE hfile;
  339. OFSTRUCT ofstruct;
  340. switch (message)
  341. {
  342. case WM_INITDIALOG: // initialize values and focus
  343. SetClassLongPtr(hDlg, GCLP_HICON, (LONG_PTR)LoadIcon(hInst,"setup"));
  344. SetDlgItemText(hDlg, IDV_MTTF, ResultsFile);
  345. SetDlgItemText(hDlg, IDV_NAMES, NameFile);
  346. SetDlgItemInt(hDlg, IDV_PERIOD, PollingPeriod, FALSE);
  347. defPP=PollingPeriod;
  348. return TRUE;
  349. case WM_CLOSE:
  350. case WM_DESTROY:
  351. case WM_ENDSESSION:
  352. case WM_QUIT:
  353. EndDialog(hDlg,FALSE);
  354. break;
  355. case WM_COMMAND: // something happened (button, listbox, combo)
  356. switch(LOWORD(wParam)) // which one
  357. {
  358. //
  359. // OK: Other problem encountered increment # of others.
  360. //
  361. case IDOK:
  362. GetDlgItemText(hDlg, IDV_MTTF, ResultsFile, MAX_DIR);
  363. if (HFILE_ERROR==OpenFile(ResultsFile, &ofstruct, OF_EXIST|OF_SHARE_DENY_NONE)) {
  364. if (HFILE_ERROR==(hfile=OpenFile(ResultsFile, &ofstruct, OF_CREATE|OF_SHARE_DENY_NONE))) {
  365. if (IDRETRY==MessageBox(NULL,
  366. "File does not exist and cannot create file.\n\n"
  367. "Press Retry to reenter filename\n"
  368. "Press Cancel to use filename anyway",
  369. "Invalid file name",
  370. MB_ICONHAND|MB_RETRYCANCEL)) {
  371. SetFocus(GetDlgItem(hDlg, IDV_MTTF));
  372. return FALSE;
  373. }
  374. } else {
  375. _lclose(hfile);
  376. }
  377. }
  378. GetDlgItemText(hDlg, IDV_NAMES, NameFile, MAX_DIR);
  379. if (HFILE_ERROR==OpenFile(NameFile, &ofstruct, OF_EXIST|OF_SHARE_DENY_NONE)) {
  380. if (HFILE_ERROR==(hfile=OpenFile(NameFile, &ofstruct, OF_CREATE|OF_SHARE_DENY_NONE))) {
  381. if (IDRETRY==MessageBox(NULL,
  382. "File does not exist and cannot create file.\n\n"
  383. "Press Retry to reenter or Cancel to use filename anyway.",
  384. "Invalid file name",
  385. MB_RETRYCANCEL)) {
  386. SetFocus(GetDlgItem(hDlg, IDV_NAMES));
  387. return FALSE;
  388. }
  389. } else {
  390. _lclose(hfile);
  391. }
  392. }
  393. PollingPeriod = GetDlgItemInt(hDlg, IDV_PERIOD, &Translated, FALSE);
  394. if (PollingPeriod<=0 || PollingPeriod > MAX_POLLING_PERIOD) {
  395. sprintf(Buffer,
  396. "Polling period must be in the range [1, %d] (default %d)",
  397. MAX_POLLING_PERIOD,
  398. defPP);
  399. MessageBox(NULL,
  400. Buffer,
  401. "Invalid Polling Period",
  402. MB_OK|MB_ICONHAND);
  403. SetDlgItemInt(hDlg, IDV_PERIOD, defPP, FALSE);
  404. SetFocus(GetDlgItem(hDlg, IDV_PERIOD));
  405. return (FALSE);
  406. }
  407. EndDialog(hDlg, TRUE);
  408. break;
  409. //
  410. // CANCEL: Dismiss dialog (use defaults)
  411. //
  412. case IDCANCEL:
  413. EndDialog(hDlg,FALSE);
  414. break;
  415. //
  416. // HELP: Descriptive message box (.HLP file would be overkill)
  417. //
  418. case IDB_HELP:
  419. MessageBox( NULL,
  420. "Mttf tracks the amount of time your machine stays up, "
  421. "the number of cold and warm boots, and "
  422. "the number of other problems that occur on your machine. "
  423. "All this information is written to a server that is "
  424. "specified in mttf.ini (in your Windows NT directory).\n\n"
  425. "This part of setup requests the server paths for the data "
  426. "files for Mttf. The Mttf data file contains the time and "
  427. "cpu usage data for all machines pointing to this server. "
  428. "The Names file is just a list of all machines running mttf. "
  429. "These files should both be in UNC (\\\\srv\\shr) format.\n\n"
  430. "If your machine is not on the network where your mttf data "
  431. "file (or names file) is, just leave these fields blank and "
  432. "a small mttf.dat will be kept in the root of your c: drive. "
  433. "Send this in when results are requested.\n\n"
  434. "The other entry here is for the period (in minutes) that data "
  435. "will be sent to the server. More machines running to one "
  436. "server would mean a higher polling period would be helpful. "
  437. "Between 10 and 30 minutes seems optimal.",
  438. "Mean Time to Failure Setup Help",
  439. MB_OK
  440. );
  441. return (TRUE);
  442. case IDV_LABEL_MTTF:
  443. case IDV_LABEL_NAMES:
  444. case IDV_LABEL_PERIOD:
  445. SetFocus(GetDlgItem(hDlg,1+LOWORD(wParam)));
  446. break;
  447. default:
  448. ;
  449. } // switch (LOWORD(wParam))
  450. break;
  451. default:
  452. ;
  453. } // switch (message)
  454. return FALSE;
  455. } // EventDlgProc()