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.

1135 lines
50 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. perfmon5.c
  5. Abstract:
  6. Program to adapt the command line Perfmon from NT4 and prior
  7. to the MMC & NT5 compatible format
  8. Author:
  9. Bob Watson (bobw) 11 may 99
  10. Revision History:
  11. --*/
  12. #define _OUTPUT_HTML 1
  13. //#define _DBG_MSG_PRINT 1
  14. #define _USE_MMC 1
  15. #define MAXSTR 1024
  16. #define MAX_ARG_STR 2048
  17. #include "perfmon5.h"
  18. #include "strsafe.h"
  19. #define MemAlloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)
  20. #define MemReAlloc(h,s) HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, h, s)
  21. #define MemFree(h) if (h != NULL) { HeapFree(GetProcessHeap(), 0, h); }
  22. #define MemSize(h) ((h != NULL) ? HeapSize(GetPRocessHeap(), 0, h) : 0)
  23. // static & global variables
  24. #ifdef _USE_MMC
  25. LPCWSTR szMmcExeCmd = (LPCWSTR) L"%windir%\\system32\\mmc.exe";
  26. LPCWSTR szMmcExeArg = (LPCWSTR) L" %windir%\\system32\\perfmon.msc /s";
  27. #else
  28. LPCWSTR szMmcExeCmd = (LPCWSTR) L"%windir%\\explorer.exe";
  29. LPCWSTR szMmcExeArg = (LPCWSTR) L" ";
  30. #endif
  31. LPCWSTR szMmcExeSetsArg = (LPCWSTR) L"/SYSMON%ws_SETTINGS \"%ws\"";
  32. LPCWSTR szMmcExeSetsLogOpt = (LPCWSTR) L"LOG";
  33. LPCWSTR szEmpty = (LPCWSTR)L"";
  34. //HTML Formatting definitions
  35. // these are not localized
  36. LPCWSTR szHtmlHeader = (LPCWSTR) L"\
  37. <HTML>\r\n\
  38. <HEAD>\r\n\
  39. <META NAME=\"GENERATOR\" Content=\"Microsoft System Monitor\">\r\n\
  40. <META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\r\n\
  41. </HEAD><BODY bgcolor=\"#%6.6x\">\r\n";
  42. LPCWSTR szObjectHeader = (LPCWSTR) L"\
  43. <OBJECT ID=\"%s\" WIDTH=\"100%%\" HEIGHT=\"100%%\"\r\n\
  44. CLASSID=\"CLSID:C4D2D8E0-D1DD-11CE-940F-008029004347\">\r\n\
  45. <PARAM NAME=\"Version\" VALUE=\"196611\"\r\n";
  46. LPCWSTR szObjectFooter = (LPCWSTR) L"\
  47. </OBJECT>\r\n";
  48. LPCWSTR szHtmlFooter = (LPCWSTR) L"\
  49. </BODY>\r\n\
  50. </HTML>\r\n";
  51. LPCWSTR szHtmlDecimalParamFmt = (LPCWSTR) L" <PARAM NAME=\"%s\" VALUE=\"%d\">\r\n";
  52. LPCWSTR szHtmlStringParamFmt = (LPCWSTR) L" <PARAM NAME=\"%s\" VALUE=\"%s\">\r\n";
  53. LPCWSTR szHtmlWideStringParamFmt = (LPCWSTR) L" <PARAM NAME=\"%s\" VALUE=\"%ws\">\r\n";
  54. LPCWSTR szHtmlLineDecimalParamFmt = (LPCWSTR) L" <PARAM NAME=\"Counter%5.5d.%s\" VALUE=\"%d\">\r\n";
  55. LPCWSTR szHtmlLineRealParamFmt = (LPCWSTR) L" <PARAM NAME=\"Counter%5.5d.%s\" VALUE=\"%f\">\r\n";
  56. LPCWSTR szHtmlLineStringParamFmt = (LPCWSTR) L" <PARAM NAME=\"Counter%5.5d.%s\" VALUE=\"%s\">\r\n";
  57. LPCWSTR szSingleObjectName = (LPCWSTR) L"SystemMonitor1";
  58. LPCWSTR szSysmonControlIdFmt = (LPCWSTR) L"SysmonControl%d";
  59. // CODE STARTS HERE
  60. LPWSTR
  61. DiskStringRead(
  62. PDISKSTRING pDS
  63. )
  64. {
  65. LPWSTR szReturnString = NULL;
  66. if (pDS->dwLength == 0) {
  67. szReturnString = NULL;
  68. }
  69. else {
  70. szReturnString = MemAlloc((pDS->dwLength + 1) * sizeof(WCHAR));
  71. if (szReturnString) {
  72. StringCchCopyW(szReturnString,
  73. pDS->dwLength + 1,
  74. (LPWSTR) (((LPBYTE) pDS) + pDS->dwOffset));
  75. }
  76. }
  77. return (szReturnString);
  78. }
  79. BOOL
  80. FileRead(
  81. HANDLE hFile,
  82. LPVOID lpMemory,
  83. DWORD nAmtToRead
  84. )
  85. {
  86. BOOL bSuccess;
  87. DWORD nAmtRead;
  88. bSuccess = ReadFile(hFile, lpMemory, nAmtToRead, & nAmtRead, NULL);
  89. return (bSuccess && (nAmtRead == nAmtToRead));
  90. }
  91. BOOL
  92. ReadLogLine(
  93. HANDLE hFile,
  94. FILE * fOutFile,
  95. LPDWORD pdwLineNo,
  96. DWORD dwInFileType,
  97. PDISKLINE * ppDiskLine,
  98. DWORD * pSizeofDiskLine
  99. )
  100. /*
  101. Effect: Read in a line from the file hFile, at the current file
  102. position.
  103. Internals: The very first characters are a line signature, then a
  104. length integer. If the signature is correct, then allocate
  105. the length amount, and work with that.
  106. */
  107. {
  108. #ifdef _OUTPUT_HTML
  109. PDH_COUNTER_PATH_ELEMENTS_W pdhPathElem;
  110. LPWSTR wszCounterPath = NULL;
  111. PDH_STATUS pdhStatus;
  112. DWORD dwCounterPathSize = 0;
  113. #endif
  114. LOGENTRY LogEntry;
  115. BOOL bReturn = TRUE;
  116. UNREFERENCED_PARAMETER(dwInFileType);
  117. UNREFERENCED_PARAMETER(ppDiskLine);
  118. UNREFERENCED_PARAMETER(pSizeofDiskLine);
  119. //=============================//
  120. // read and compare signature //
  121. //=============================//
  122. if (! FileRead(hFile, & LogEntry, sizeof(LOGENTRY) - sizeof(LogEntry.pNextLogEntry))) {
  123. return (FALSE);
  124. }
  125. #ifdef _OUTPUT_HTML
  126. // expand log entry into counters: not this may not always work!
  127. if (lstrcmpW(LogEntry.szComputer, (LPCWSTR) L"....") != 0) {
  128. // then add the machine name
  129. pdhPathElem.szMachineName = LogEntry.szComputer;
  130. }
  131. else {
  132. pdhPathElem.szMachineName = NULL;
  133. }
  134. pdhPathElem.szObjectName = LogEntry.szObject;
  135. pdhPathElem.szInstanceName = (LPWSTR) L"*";
  136. pdhPathElem.szParentInstance = NULL;
  137. pdhPathElem.dwInstanceIndex = (DWORD) -1;
  138. pdhPathElem.szCounterName = (LPWSTR) L"*";
  139. pdhStatus = PdhMakeCounterPathW(& pdhPathElem, wszCounterPath, & dwCounterPathSize, 0);
  140. while (pdhStatus == PDH_MORE_DATA) {
  141. MemFree(wszCounterPath);
  142. wszCounterPath = MemAlloc(dwCounterPathSize * sizeof(WCHAR));
  143. if (wszCounterPath != NULL) {
  144. pdhStatus = PdhMakeCounterPathW(& pdhPathElem, wszCounterPath, & dwCounterPathSize, 0);
  145. }
  146. else {
  147. pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  148. }
  149. }
  150. if (pdhStatus == ERROR_SUCCESS) {
  151. fwprintf(fOutFile, szHtmlLineStringParamFmt, * pdwLineNo, (LPCWSTR) L"Path", wszCounterPath);
  152. * pdwLineNo = * pdwLineNo + 1; // increment the line no
  153. }
  154. else {
  155. bReturn = FALSE;
  156. }
  157. MemFree(wszCounterPath);
  158. #else
  159. fprintf(fOutFile, "\n Line[%3.3d].ObjectTitleIndex = %d", * pdwLineNo, LogEntry.ObjectTitleIndex);
  160. fprintf(fOutFile, "\n Line[%3.3d].szComputer = %ws", * pdwLineNo, LogEntry.szComputer);
  161. fprintf(fOutFile, "\n Line[%3.3d].szObject = %ws", * pdwLineNo, LogEntry.szObject);
  162. fprintf(fOutFile, "\n Line[%3.3d].bSaveCurrentName = %d", * pdwLineNo, LogEntry.bSaveCurrentName);
  163. * pdwLineNo = * pdwLineNo + 1; // increment the line no
  164. #endif
  165. return bReturn;
  166. }
  167. BOOL
  168. ReadLine(
  169. HANDLE hFile,
  170. FILE * fOutFile,
  171. LPDWORD pdwLineNo,
  172. DWORD dwInFileType,
  173. PDISKLINE * ppDiskLine,
  174. DWORD * pSizeofDiskLine
  175. )
  176. /*
  177. Effect: Read in a line from the file hFile, at the current file
  178. position.
  179. Internals: The very first characters are a line signature, then a
  180. length integer. If the signature is correct, then allocate
  181. the length amount, and work with that.
  182. */
  183. {
  184. PDISKLINE pDiskLine = NULL;
  185. DWORD dwLineNo = * pdwLineNo;
  186. #ifdef _OUTPUT_HTML
  187. double dScaleFactor;
  188. PDH_STATUS pdhStatus;
  189. PDH_COUNTER_PATH_ELEMENTS_W pdhPathElem;
  190. LPWSTR wszCounterPath = NULL;
  191. DWORD dwCounterPathSize = 0;
  192. #else
  193. LPWSTR szTempString = NULL;
  194. #endif
  195. BOOL bReturn = FALSE;
  196. struct {
  197. DWORD dwSignature;
  198. DWORD dwLength;
  199. } LineHeader;
  200. //=============================//
  201. // read and compare signature //
  202. //=============================//
  203. if (! FileRead(hFile, & LineHeader, sizeof(LineHeader))) {
  204. goto Cleanup;
  205. }
  206. if (LineHeader.dwSignature != dwLineSignature || LineHeader.dwLength == 0) {
  207. SetLastError(ERROR_BAD_FORMAT);
  208. goto Cleanup;
  209. }
  210. //=============================//
  211. // read and allocate length //
  212. //=============================//
  213. // if (!FileRead (hFile, &dwLength, sizeof (dwLength)) || dwLength == 0)
  214. // return (NULL) ;
  215. // check if we need a bigger buffer,
  216. // normally, it should be the same except the first time...
  217. if (LineHeader.dwLength > * pSizeofDiskLine) {
  218. MemFree(* ppDiskLine);
  219. * pSizeofDiskLine = 0;
  220. // re-allocate a new buffer
  221. * ppDiskLine = (PDISKLINE) MemAlloc(LineHeader.dwLength);
  222. if ((* ppDiskLine) == NULL) {
  223. // no memory, should flag an error...
  224. goto Cleanup;
  225. }
  226. * pSizeofDiskLine = LineHeader.dwLength;
  227. }
  228. pDiskLine = * ppDiskLine;
  229. //=============================//
  230. // copy diskline, alloc line //
  231. //=============================//
  232. if (! FileRead(hFile, pDiskLine, LineHeader.dwLength)) {
  233. goto Cleanup;
  234. }
  235. #ifdef _OUTPUT_HTML
  236. // HTML output requires 1 based indexes, not 0 based
  237. dwLineNo += 1;
  238. // make counter path string out of components
  239. pdhPathElem.szMachineName = DiskStringRead(& (pDiskLine->dsSystemName));
  240. if (pdhPathElem.szMachineName != NULL
  241. && lstrcmpW(pdhPathElem.szMachineName, (LPCWSTR) L"....") == 0) {
  242. // then use local machine
  243. MemFree(pdhPathElem.szMachineName);
  244. pdhPathElem.szMachineName = NULL;
  245. }
  246. pdhPathElem.szObjectName = DiskStringRead(& (pDiskLine->dsObjectName));
  247. if (pDiskLine->dwUniqueID != PERF_NO_UNIQUE_ID) {
  248. pdhPathElem.szInstanceName = MemAlloc(MAXSTR);
  249. if (pdhPathElem.szInstanceName != NULL) {
  250. _ltow(pDiskLine->dwUniqueID, pdhPathElem.szInstanceName, 10);
  251. }
  252. }
  253. else {
  254. pdhPathElem.szInstanceName = DiskStringRead(& (pDiskLine->dsInstanceName));
  255. }
  256. pdhPathElem.szParentInstance = DiskStringRead( &(pDiskLine->dsPINName));
  257. pdhPathElem.dwInstanceIndex = (DWORD) -1;
  258. pdhPathElem.szCounterName = DiskStringRead( &(pDiskLine->dsCounterName));
  259. pdhStatus = PdhMakeCounterPathW(& pdhPathElem, wszCounterPath, & dwCounterPathSize, 0);
  260. while (pdhStatus == PDH_MORE_DATA) {
  261. MemFree(wszCounterPath);
  262. wszCounterPath = MemAlloc(dwCounterPathSize * sizeof(WCHAR));
  263. if (wszCounterPath != NULL) {
  264. pdhStatus = PdhMakeCounterPathW(& pdhPathElem, wszCounterPath, & dwCounterPathSize, 0);
  265. }
  266. else {
  267. pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  268. }
  269. }
  270. if (pdhStatus == ERROR_SUCCESS) {
  271. fwprintf(fOutFile, szHtmlLineStringParamFmt, dwLineNo, (LPCWSTR) L"Path", wszCounterPath);
  272. if (dwInFileType == PMC_FILE) {
  273. dScaleFactor = log10(pDiskLine->eScale);
  274. dScaleFactor += 0.5;
  275. dScaleFactor = floor(dScaleFactor);
  276. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"ScaleFactor", (LONG) dScaleFactor);
  277. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"Color", * (DWORD *) & pDiskLine->Visual.crColor);
  278. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"LineStyle", pDiskLine->Visual.iStyle );
  279. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"Width", pDiskLine->Visual.iWidth);
  280. }
  281. if (dwInFileType == PMA_FILE) {
  282. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"AlertOverUnder", pDiskLine->bAlertOver);
  283. fwprintf(fOutFile, szHtmlLineRealParamFmt, dwLineNo, (LPCWSTR) L"AlertThreshold", pDiskLine->eAlertValue);
  284. fwprintf(fOutFile, szHtmlLineDecimalParamFmt, dwLineNo, (LPCWSTR) L"Color", * (DWORD *) & pDiskLine->Visual.crColor);
  285. }
  286. bReturn = TRUE;
  287. }
  288. MemFree(wszCounterPath);
  289. MemFree(pdhPathElem.szMachineName);
  290. MemFree(pdhPathElem.szObjectName);
  291. MemFree(pdhPathElem.szInstanceName);
  292. MemFree(pdhPathElem.szParentInstance);
  293. MemFree(pdhPathElem.szCounterName);
  294. #else
  295. UNREFERENCED_PARAMETER(dwInFileType);
  296. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].iLineType = %d", dwLineNo, pDiskLine->iLineType);
  297. szTempString = DiskStringRead(& (pDiskLine->dsSystemName));
  298. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsSystmeName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  299. MemFree(szTempString);
  300. szTempString = DiskStringRead(& (pDiskLine->dsObjectName));
  301. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsObjectName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  302. MemFree(szTempString);
  303. szTempString = DiskStringRead(& (pDiskLine->dsCounterName));
  304. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsCounterName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  305. MemFree(szTempString);
  306. szTempString = DiskStringRead(& (pDiskLine->dsInstanceName));
  307. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsInstanceName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  308. MemFree(szTempString);
  309. szTempString = DiskStringRead(& (pDiskLine->dsPINName));
  310. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsPINName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  311. MemFree(szTempString);
  312. szTempString = DiskStringRead(& (pDiskLine->dsParentObjName));
  313. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsParentObjName = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  314. MemFree(szTempString);
  315. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dwUniqueID = 0x%8.8x", dwLineNo, pDiskLine->dwUniqueID);
  316. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].iScaleIndex = %d", dwLineNo, pDiskLine->iScaleIndex);
  317. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].eScale = %e", dwLineNo, pDiskLine->eScale);
  318. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].bAlertOver = %d", dwLineNo, pDiskLine->bAlertOver);
  319. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].eAlertValue = %e", dwLineNo, pDiskLine->eAlertValue);
  320. szTempString = DiskStringRead(& (pDiskLine->dsAlertProgram));
  321. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].dsAlertProgram = %ws", dwLineNo, (szTempString ? szTempString : (LPCWSTR)L""));
  322. MemFree(szTempString);
  323. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].bEveryTime = %d", dwLineNo, pDiskLine->bEveryTime);
  324. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.crColor = 0x%8.8x", dwLineNo, *(DWORD *)&pDiskLine->Visual.crColor) ;
  325. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.iColorIndex = %d", dwLineNo, pDiskLine->Visual.iColorIndex );
  326. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.iStyle = %d", dwLineNo, pDiskLine->Visual.iStyle );
  327. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.iStyleIndex = %d", dwLineNo, pDiskLine->Visual.iStyleIndex );
  328. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.iWidth = %d", dwLineNo, pDiskLine->Visual.iWidth );
  329. fwprintf(fOutFile, (LPCWSTR) L"\n Line[%3.3d].LV.iWidthIndex = %d", dwLineNo, pDiskLine->Visual.iWidthIndex );
  330. bReturn = TRUE;
  331. #endif
  332. Cleanup:
  333. return bReturn;
  334. }
  335. void
  336. ReadLines(
  337. HANDLE hFile,
  338. FILE * fOutFile,
  339. DWORD dwFileType,
  340. DWORD dwNumLines
  341. )
  342. {
  343. DWORD i;
  344. PDISKLINE pDiskLine = NULL;
  345. DWORD SizeofDiskLine = 0; // bytes in pDiskLine
  346. DWORD dwLogLineNo;
  347. SizeofDiskLine = MAX_PATH;
  348. for (i = 0, dwLogLineNo = 1; i < dwNumLines ; i ++) {
  349. if (dwFileType == PML_FILE) {
  350. ReadLogLine(hFile, fOutFile, & dwLogLineNo, dwFileType, & pDiskLine, & SizeofDiskLine);
  351. }
  352. else {
  353. ReadLine(hFile, fOutFile, & i, dwFileType, & pDiskLine, & SizeofDiskLine);
  354. }
  355. }
  356. MemFree(pDiskLine);
  357. }
  358. BOOL
  359. OpenAlert(
  360. LPCWSTR szInFileName,
  361. HANDLE hFile,
  362. FILE * fOutFile,
  363. LPCWSTR szObjectName
  364. )
  365. { // OpenAlert
  366. DISKALERT DiskAlert;
  367. BOOL bSuccess = TRUE ;
  368. DWORD dwLocalActionFlags = 0;
  369. #ifdef _OUTPUT_HTML
  370. WCHAR szComment[MAX_PATH];
  371. WCHAR path[_MAX_PATH];
  372. WCHAR drive[_MAX_DRIVE];
  373. WCHAR dir[_MAX_DIR];
  374. WCHAR fname[_MAX_FNAME];
  375. WCHAR ext[_MAX_EXT];
  376. #endif
  377. // read the next section if valid
  378. bSuccess = FileRead (hFile, &DiskAlert, sizeof (DISKALERT));
  379. if (bSuccess) {
  380. #ifdef _OUTPUT_HTML
  381. if (DiskAlert.dwNumLines > 0) {
  382. fwprintf(fOutFile, szObjectHeader, szObjectName);
  383. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ManualUpdate", DiskAlert.bManualRefresh);
  384. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowToolbar", DiskAlert.perfmonOptions.bMenubar);
  385. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"UpdateInterval", (int) DiskAlert.dwIntervalSecs / 1000);
  386. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"SampleIntervalUnitType", 1); // Seconds
  387. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"SampleIntervalValue", (int) DiskAlert.dwIntervalSecs / 1000);
  388. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"CommandFile", "");
  389. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"UserText", "");
  390. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"PerfLogName", "");
  391. dwLocalActionFlags |= 1; // perfmon normally logs to the UI, but we don't have one
  392. // so log to the event log by default
  393. if (DiskAlert.bNetworkAlert) {
  394. dwLocalActionFlags |= 2;
  395. }
  396. // perfmon does 1 net name per alert. we do 1 per file so leave it blank
  397. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"NetworkName", "");
  398. dwLocalActionFlags |= 0x00003F00; // command line flags
  399. fwprintf (fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ActionFlags",dwLocalActionFlags);
  400. // set the defaults to duplicate a perfmon log
  401. _wfullpath(path, szInFileName, _MAX_PATH);
  402. _wsplitpath(path, drive, dir, fname, ext);
  403. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"AlertName", fname);
  404. ZeroMemory(szComment, MAX_PATH * sizeof(WCHAR));
  405. StringCchPrintfW(szComment,
  406. MAX_PATH,
  407. (LPCWSTR) L"Created from Perfmon Settings File \"%ws%ws\"", fname, ext);
  408. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"Comment", szComment);
  409. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogType", 2); // Sysmon alert
  410. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileMaxSize", -1); // no size limit
  411. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogFileBaseName", fname);
  412. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileSerialNumber", 1);
  413. ZeroMemory(szComment, MAX_PATH * sizeof(WCHAR));
  414. StringCchPrintfW(szComment,
  415. MAX_PATH,
  416. (LPCWSTR) L"%ws%ws", drive, dir);
  417. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogFileFolder", szComment);
  418. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileAutoFormat", 0); //no auto name
  419. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileType", 2); // PDH binary counter log
  420. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"StartMode", 0); // manual start
  421. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"StopMode", 0); // manual stop
  422. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"RestartMode", 0); // no restart
  423. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"EOFCommandFile", "");
  424. // Get ready to list the counters
  425. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"CounterCount", DiskAlert.dwNumLines);
  426. }
  427. #else // output text
  428. UNREFERENCED_PARAMETER(szInFileName);
  429. UNREFERENCED_PARAMETER(szOutFileName);
  430. // dump settings file header
  431. fOutFile = stdout;
  432. fprintf(fOutFile, "\nDA.dwNumLines = %d", DiskAlert.dwNumLines);
  433. fprintf(fOutFile, "\nDA.dwIntervalSecs = %d", DiskAlert.dwIntervalSecs);
  434. fprintf(fOutFile, "\nDA.bManualRefresh = %d", DiskAlert.bManualRefresh);
  435. fprintf(fOutFile, "\nDA.bSwitchToAlert = %d", DiskAlert.bSwitchToAlert);
  436. fprintf(fOutFile, "\nDA.bNetworkAlert = %d", DiskAlert.bNetworkAlert);
  437. fprintf(fOutFile, "\nDA.MessageName = %16.16ws", DiskAlert.MessageName);
  438. fprintf(fOutFile, "\nDA.MiscOptions = 0x%8.8x", DiskAlert.MiscOptions);
  439. fprintf(fOutFile, "\nDA.LV.crColor = 0x%8.8x", * (DWORD *) & DiskAlert.Visual.crColor);
  440. fprintf(fOutFile, "\nDA.LV.iColorIndex = %d", DiskAlert.Visual.iColorIndex);
  441. fprintf(fOutFile, "\nDA.LV.iStyle = %d", DiskAlert.Visual.iStyle);
  442. fprintf(fOutFile, "\nDA.LV.iStyleIndex = %d", DiskAlert.Visual.iStyleIndex);
  443. fprintf(fOutFile, "\nDA.LV.iWidth = %d", DiskAlert.Visual.iWidth);
  444. fprintf(fOutFile, "\nDA.LV.iWidthIndex = %d", DiskAlert.Visual.iWidthIndex);
  445. fprintf(fOutFile, "\nDA.PO.bMenubar = %d", DiskAlert.perfmonOptions.bMenubar);
  446. fprintf(fOutFile, "\nDA.PO.bToolbar = %d", DiskAlert.perfmonOptions.bToolbar);
  447. fprintf(fOutFile, "\nDA.PO.bStatusbar = %d", DiskAlert.perfmonOptions.bStatusbar);
  448. fprintf(fOutFile, "\nDA.PO.bAlwaysOnTop = %d", DiskAlert.perfmonOptions.bAlwaysOnTop);
  449. #endif
  450. }
  451. if ((bSuccess) && (DiskAlert.dwNumLines > 0)) {
  452. ReadLines(hFile, fOutFile, PMA_FILE, DiskAlert.dwNumLines);
  453. #ifdef _OUTPUT_HTML
  454. fwprintf(fOutFile, szObjectFooter);
  455. #endif
  456. }
  457. return (bSuccess);
  458. } // OpenAlert
  459. BOOL
  460. OpenLog(
  461. LPCWSTR szInFileName,
  462. HANDLE hFile,
  463. FILE * fOutFile,
  464. LPCWSTR szObjectName
  465. )
  466. { // OpenLog
  467. DISKLOG DiskLog;
  468. BOOL bSuccess = TRUE;
  469. #ifdef _OUTPUT_HTML
  470. WCHAR szComment[MAX_PATH];
  471. WCHAR path[_MAX_PATH];
  472. WCHAR drive[_MAX_DRIVE];
  473. WCHAR dir[_MAX_DIR];
  474. WCHAR fname[_MAX_FNAME];
  475. WCHAR ext[_MAX_EXT];
  476. #endif
  477. // read the next section if valid
  478. bSuccess = FileRead(hFile, & DiskLog, sizeof(DISKLOG));
  479. if (bSuccess) {
  480. #ifdef _OUTPUT_HTML
  481. if (DiskLog.dwNumLines > 0) {
  482. fwprintf(fOutFile, szObjectHeader, szObjectName);
  483. // dump settings file header
  484. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ManualUpdate", DiskLog.bManualRefresh);
  485. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"UpdateInterval", (int) DiskLog.dwIntervalSecs / 1000);
  486. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"SampleIntervalUnitType", 1); // Seconds
  487. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"SampleIntervalValue", (int) DiskLog.dwIntervalSecs / 1000);
  488. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogFileName", DiskLog.LogFileName);
  489. // set the defaults to duplicate a perfmon log
  490. _wfullpath(path, szInFileName, _MAX_PATH);
  491. _wsplitpath(path, drive, dir, fname, ext);
  492. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogName", fname);
  493. ZeroMemory(szComment, MAX_PATH * sizeof(WCHAR));
  494. StringCchPrintfW(szComment,
  495. MAX_PATH,
  496. (LPCWSTR) L"Created from Perfmon Settings File \"%ws%ws\"",
  497. fname, ext);
  498. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"Comment", szComment);
  499. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogType", 0); // PDH counter log
  500. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileMaxSize", -1); // no size limit
  501. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogFileBaseName", fname);
  502. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileSerialNumber", 1);
  503. ZeroMemory(szComment, MAX_PATH * sizeof(WCHAR));
  504. StringCchPrintfW(szComment, MAX_PATH, (LPCWSTR) L"%ws%ws", drive, dir);
  505. fwprintf(fOutFile, szHtmlWideStringParamFmt, (LPCWSTR) L"LogFileFolder", szComment);
  506. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileAutoFormat", 0); //no auto name
  507. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"LogFileType", 2); // PDH binary counter log
  508. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"StartMode", 0); // manual start
  509. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"StopMode", 0); // manual stop
  510. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"RestartMode", 0); // no restart
  511. fwprintf(fOutFile, szHtmlStringParamFmt, (LPCWSTR) L"EOFCommandFile", "");
  512. // Get ready to list the counters
  513. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"CounterCount", DiskLog.dwNumLines);
  514. }
  515. #else // output text
  516. UNREFERENCED_PARAMETER(szInFileName);
  517. // dump settings file header
  518. fOutFile = stdout;
  519. fprintf(fOutFile, "\nDL.dwNumLines = %d", DiskLog.dwNumLines);
  520. fprintf(fOutFile, "\nDL.bManualRefresh = %d", DiskLog.bManualRefresh);
  521. fprintf(fOutFile, "\nDL.dwIntervalSecs = %d", DiskLog.dwIntervalSecs);
  522. fprintf(fOutFile, "\nDL.LogFileName = %ws", DiskLog.LogFileName);
  523. fprintf(fOutFile, "\nDC.PO.bMenubar = %d", DiskLog.perfmonOptions.bMenubar);
  524. fprintf(fOutFile, "\nDC.PO.bToolbar = %d", DiskLog.perfmonOptions.bToolbar);
  525. fprintf(fOutFile, "\nDC.PO.bStatusbar = %d", DiskLog.perfmonOptions.bStatusbar);
  526. fprintf(fOutFile, "\nDC.PO.bAlwaysOnTop = %d", DiskLog.perfmonOptions.bAlwaysOnTop);
  527. #endif
  528. }
  529. if ((bSuccess) && (DiskLog.dwNumLines > 0)) {
  530. //the log settings file requires a special function to read the lines from
  531. ReadLines(hFile, fOutFile, PML_FILE, DiskLog.dwNumLines);
  532. #ifdef _OUTPUT_HTML
  533. fwprintf(fOutFile, szObjectFooter);
  534. #endif
  535. }
  536. return (bSuccess) ;
  537. } // OpenLog
  538. BOOL
  539. OpenReport(
  540. HANDLE hFile,
  541. FILE * fOutFile,
  542. LPCWSTR szObjectName
  543. )
  544. { // OpenReport
  545. DISKREPORT DiskReport;
  546. BOOL bSuccess = TRUE;
  547. DWORD dwColor;
  548. // read the next section if valid
  549. bSuccess = FileRead(hFile, & DiskReport, sizeof(DISKREPORT));
  550. if (bSuccess) {
  551. #ifdef _OUTPUT_HTML
  552. if (DiskReport.dwNumLines > 0) {
  553. // dump settings file header
  554. fwprintf(fOutFile, szObjectHeader, szObjectName);
  555. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ManualUpdate", DiskReport.bManualRefresh);
  556. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowToolbar", DiskReport.perfmonOptions.bToolbar);
  557. // report intervals are reported in mS
  558. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"UpdateInterval", (int) DiskReport.dwIntervalSecs / 1000);
  559. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"DisplayType", 3); // report type
  560. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ReportValueType", 0); // default display value
  561. // derive the following from the current windows environment
  562. dwColor = GetSysColor(COLOR_WINDOW);
  563. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BackColor", dwColor);
  564. dwColor = GetSysColor(COLOR_3DFACE);
  565. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BackColorCtl", dwColor);
  566. dwColor = GetSysColor(COLOR_BTNTEXT);
  567. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ForeColor", dwColor);
  568. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"GridColor", dwColor);
  569. dwColor = 0x00FF0000; // red
  570. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"TimeBarColor", dwColor);
  571. // other perfmon settings that are assumed by perfmon but
  572. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"Appearance", 1); // 3d appearance
  573. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BorderStyle", 0); // no border
  574. // Get ready to list the counters
  575. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"CounterCount", DiskReport.dwNumLines);
  576. } // else no counters to dump
  577. #else // output text
  578. // dump settings file header
  579. fprintf(fOutFile, "\nDR.dwNumLines = %d", DiskReport.dwNumLines);
  580. fprintf(fOutFile, "\nDR.bManualRefresh = %d", DiskReport.bManualRefresh);
  581. fprintf(fOutFile, "\nDC.dwIntervalSecs = %d", DiskReport.dwIntervalSecs);
  582. fprintf(fOutFile, "\nDR.LV.crColor = 0x%8.8x", * (DWORD *) & DiskReport.Visual.crColor);
  583. fprintf(fOutFile, "\nDR.LV.iColorIndex = %d", DiskReport.Visual.iColorIndex);
  584. fprintf(fOutFile, "\nDR.LV.iStyle = %d", DiskReport.Visual.iStyle);
  585. fprintf(fOutFile, "\nDR.LV.iStyleIndex = %d", DiskReport.Visual.iStyleIndex);
  586. fprintf(fOutFile, "\nDR.LV.iWidth = %d", DiskReport.Visual.iWidth);
  587. fprintf(fOutFile, "\nDR.LV.iWidthIndex = %d", DiskReport.Visual.iWidthIndex);
  588. fprintf(fOutFile, "\nDC.PO.bMenubar = %d", DiskReport.perfmonOptions.bMenubar);
  589. fprintf(fOutFile, "\nDC.PO.bToolbar = %d", DiskReport.perfmonOptions.bToolbar);
  590. fprintf(fOutFile, "\nDC.PO.bStatusbar = %d", DiskReport.perfmonOptions.bStatusbar);
  591. fprintf(fOutFile, "\nDC.PO.bAlwaysOnTop = %d", DiskReport.perfmonOptions.bAlwaysOnTop);
  592. #endif
  593. }
  594. if ((bSuccess) && (DiskReport.dwNumLines > 0)) {
  595. ReadLines(hFile, fOutFile, PMR_FILE, DiskReport.dwNumLines);
  596. #ifdef _OUTPUT_HTML
  597. fwprintf(fOutFile, szObjectFooter);
  598. #endif
  599. }
  600. return (bSuccess);
  601. } // OpenReport
  602. BOOL
  603. OpenChart(
  604. HANDLE hFile,
  605. FILE * fOutFile,
  606. LPCWSTR szObjectName
  607. )
  608. { // OpenChart
  609. DISKCHART DiskChart;
  610. BOOL bSuccess = TRUE;
  611. DWORD dwColor;
  612. // read the next section if valid
  613. bSuccess = FileRead(hFile, & DiskChart, sizeof(DISKCHART));
  614. if (bSuccess) {
  615. #ifdef _OUTPUT_HTML
  616. if (DiskChart.dwNumLines > 0) {
  617. // dump settings file header
  618. fwprintf(fOutFile, szObjectHeader, szObjectName);
  619. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ManualUpdate", DiskChart.bManualRefresh);
  620. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowLegend", DiskChart.gOptions.bLegendChecked);
  621. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowScaleLabels", DiskChart.gOptions.bLabelsChecked);
  622. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowVerticalGrid", DiskChart.gOptions.bVertGridChecked);
  623. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowHorizontalGrid", DiskChart.gOptions.bHorzGridChecked);
  624. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ShowToolbar", DiskChart.gOptions.bMenuChecked);
  625. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"MaximumScale", DiskChart.gOptions.iVertMax);
  626. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"UpdateInterval", (int) DiskChart.gOptions.eTimeInterval);
  627. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"DisplayType", (DiskChart.gOptions.iGraphOrHistogram == BAR_GRAPH ? 2 : 1));
  628. // derive the following from the current windows environment
  629. dwColor = GetSysColor(COLOR_3DFACE);
  630. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BackColor", dwColor);
  631. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BackColorCtl", dwColor);
  632. dwColor = GetSysColor(COLOR_BTNTEXT);
  633. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"ForeColor", dwColor);
  634. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"GridColor", dwColor);
  635. dwColor = 0x00FF0000; // red
  636. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"TimeBarColor", dwColor);
  637. // other perfmon settings that are assumed by perfmon but
  638. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"Appearance", 1); // 3d appearance
  639. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"BorderStyle", 0); // no border
  640. // Get ready to list the counters
  641. fwprintf(fOutFile, szHtmlDecimalParamFmt, (LPCWSTR) L"CounterCount", DiskChart.dwNumLines);
  642. } // else no counters to display
  643. #else // output text
  644. // dump settings file header
  645. fprintf(fOutFile, "\nDC.dwNumLines = %d", DiskChart.dwNumLines);
  646. fprintf(fOutFile, "\nDC.gMaxValues = %d", DiskChart.gMaxValues);
  647. fprintf(fOutFile, "\nDC.bManualRefresh = %d", DiskChart.bManualRefresh);
  648. fprintf(fOutFile, "\nDC.LV.crColor = 0x%8.8x", * (DWORD *) & DiskChart.Visual.crColor);
  649. fprintf(fOutFile, "\nDC.LV.iColorIndex = %d", DiskChart.Visual.iColorIndex);
  650. fprintf(fOutFile, "\nDC.LV.iStyle = %d", DiskChart.Visual.iStyle);
  651. fprintf(fOutFile, "\nDC.LV.iStyleIndex = %d", DiskChart.Visual.iStyleIndex);
  652. fprintf(fOutFile, "\nDC.LV.iWidth = %d", DiskChart.Visual.iWidth);
  653. fprintf(fOutFile, "\nDC.LV.iWidthIndex = %d", DiskChart.Visual.iWidthIndex);
  654. fprintf(fOutFile, "\nDC.GO.bLegendChecked = %d", DiskChart.gOptions.bLegendChecked);
  655. fprintf(fOutFile, "\nDC.GO.bMenuChecked = %d", DiskChart.gOptions.bMenuChecked);
  656. fprintf(fOutFile, "\nDC.GO.bLabelsChecked = %d", DiskChart.gOptions.bLabelsChecked);
  657. fprintf(fOutFile, "\nDC.GO.bVertGridChecked = %d", DiskChart.gOptions.bVertGridChecked);
  658. fprintf(fOutFile, "\nDC.GO.bHorzGridChecked = %d", DiskChart.gOptions.bHorzGridChecked);
  659. fprintf(fOutFile, "\nDC.GO.bStatusBarChecked = %d", DiskChart.gOptions.bStatusBarChecked);
  660. fprintf(fOutFile, "\nDC.GO.iVertMax = %d", DiskChart.gOptions.iVertMax);
  661. fprintf(fOutFile, "\nDC.GO.eTimeInterval = %e", DiskChart.gOptions.eTimeInterval);
  662. fprintf(fOutFile, "\nDC.GO.iGraphOrHistogram = %d", DiskChart.gOptions.iGraphOrHistogram);
  663. fprintf(fOutFile, "\nDC.GO.GraphVGrid = %d", DiskChart.gOptions.GraphVGrid);
  664. fprintf(fOutFile, "\nDC.GO.GraphHGrid = %d", DiskChart.gOptions.GraphHGrid);
  665. fprintf(fOutFile, "\nDC.GO.HistVGrid = %d", DiskChart.gOptions.HistVGrid);
  666. fprintf(fOutFile, "\nDC.GO.HistHGrid = %d", DiskChart.gOptions.HistHGrid);
  667. fprintf(fOutFile, "\nDC.PO.bMenubar = %d", DiskChart.perfmonOptions.bMenubar);
  668. fprintf(fOutFile, "\nDC.PO.bToolbar = %d", DiskChart.perfmonOptions.bToolbar);
  669. fprintf(fOutFile, "\nDC.PO.bStatusbar = %d", DiskChart.perfmonOptions.bStatusbar);
  670. fprintf(fOutFile, "\nDC.PO.bAlwaysOnTop = %d", DiskChart.perfmonOptions.bAlwaysOnTop);
  671. #endif
  672. }
  673. if ((bSuccess) && (DiskChart.dwNumLines > 0)) {
  674. ReadLines(hFile, fOutFile, PMC_FILE, DiskChart.dwNumLines);
  675. #ifdef _OUTPUT_HTML
  676. fwprintf(fOutFile, szObjectFooter);
  677. #endif
  678. }
  679. return (bSuccess);
  680. } // OpenChart
  681. BOOL
  682. OpenWorkspace(
  683. LPCWSTR szPerfmonFileName,
  684. HANDLE hInFile,
  685. FILE * fOutFile
  686. )
  687. {
  688. DISKWORKSPACE DiskWorkspace;
  689. WCHAR szObjectName[MAX_PATH];
  690. DWORD dwObjectId = 1;
  691. BOOL bReturn = FALSE;
  692. if (! FileRead(hInFile, & DiskWorkspace, sizeof(DISKWORKSPACE))) {
  693. goto Exit0 ;
  694. }
  695. if (DiskWorkspace.ChartOffset == 0 &&
  696. DiskWorkspace.AlertOffset == 0 &&
  697. DiskWorkspace.LogOffset == 0 &&
  698. DiskWorkspace.ReportOffset == 0) {
  699. // no entries to process
  700. goto Exit0 ;
  701. }
  702. if (DiskWorkspace.ChartOffset) {
  703. if (FileSeekBegin(hInFile, DiskWorkspace.ChartOffset) == 0xFFFFFFFF) {
  704. goto Exit0 ;
  705. }
  706. ZeroMemory(szObjectName, MAX_PATH * sizeof(WCHAR));
  707. StringCchPrintfW(szObjectName, MAX_PATH, szSysmonControlIdFmt, dwObjectId ++);
  708. // process chart entry
  709. if (! OpenChart(hInFile, fOutFile, szObjectName)) {
  710. goto Exit0 ;
  711. }
  712. }
  713. if (DiskWorkspace.AlertOffset) {
  714. if (FileSeekBegin(hInFile, DiskWorkspace.AlertOffset) == 0xffffffff) {
  715. goto Exit0 ;
  716. }
  717. ZeroMemory(szObjectName, MAX_PATH * sizeof(WCHAR));
  718. StringCchPrintfW(szObjectName, MAX_PATH, szSysmonControlIdFmt, dwObjectId ++);
  719. if (! OpenAlert(szPerfmonFileName, hInFile, fOutFile, szObjectName)) {
  720. goto Exit0 ;
  721. }
  722. }
  723. if (DiskWorkspace.LogOffset) {
  724. if (FileSeekBegin(hInFile, DiskWorkspace.LogOffset) == 0xffffffff) {
  725. goto Exit0 ;
  726. }
  727. ZeroMemory(szObjectName, MAX_PATH * sizeof(WCHAR));
  728. StringCchPrintfW(szObjectName, MAX_PATH, szSysmonControlIdFmt, dwObjectId ++);
  729. if (! OpenLog(szPerfmonFileName, hInFile, fOutFile, szObjectName)) {
  730. goto Exit0 ;
  731. }
  732. }
  733. if (DiskWorkspace.ReportOffset) {
  734. if (FileSeekBegin(hInFile, DiskWorkspace.ReportOffset) == 0xffffffff) {
  735. goto Exit0 ;
  736. }
  737. ZeroMemory(szObjectName, MAX_PATH * sizeof(WCHAR));
  738. StringCchPrintfW(szObjectName, MAX_PATH, szSysmonControlIdFmt, dwObjectId ++);
  739. if (! OpenReport(hInFile, fOutFile, szObjectName)) {
  740. goto Exit0 ;
  741. }
  742. }
  743. bReturn = TRUE;
  744. Exit0:
  745. return bReturn;
  746. } // OpenWorkspace
  747. BOOL
  748. ConvertPerfmonFile(
  749. IN LPCWSTR szPerfmonFileName,
  750. IN LPCWSTR szSysmonFileName,
  751. IN LPDWORD pdwFileType
  752. )
  753. {
  754. HANDLE hInFile = INVALID_HANDLE_VALUE;
  755. PERFFILEHEADER pfHeader;
  756. BOOL bSuccess = FALSE;
  757. FILE * fOutFile = NULL;
  758. #ifdef _OUTPUT_HTML
  759. DWORD dwColor;
  760. #endif
  761. // open input file as read only
  762. hInFile = CreateFileW(
  763. szPerfmonFileName, // filename
  764. GENERIC_READ, // read access
  765. 0, // no sharing
  766. NULL, // default security
  767. OPEN_EXISTING, // only open existing files
  768. FILE_ATTRIBUTE_NORMAL, // normal attributes
  769. NULL); // no template file
  770. if (hInFile != INVALID_HANDLE_VALUE) {
  771. bSuccess = FileRead(hInFile, & pfHeader, sizeof(PERFFILEHEADER));
  772. if (bSuccess) {
  773. #ifdef _OUTPUT_HTML
  774. fOutFile = _wfopen(szSysmonFileName, (LPCWSTR) L"w+t");
  775. #else
  776. fOutFile = stdout;
  777. #endif
  778. if (fOutFile != NULL) {
  779. dwColor = GetSysColor(COLOR_3DFACE);
  780. fwprintf(fOutFile, szHtmlHeader, (dwColor & 0x00FFFFFF));
  781. if (lstrcmpW(pfHeader.szSignature, szPerfChartSignature) == 0) {
  782. #ifdef _DBG_MSG_PRINT
  783. fprintf(stderr, "\nConverting Chart Settings file \"%ws\" to \n \"%ws\"",
  784. szPerfmonFileName,
  785. szSysmonFileName);
  786. #endif
  787. bSuccess = OpenChart(hInFile, fOutFile, szSingleObjectName);
  788. * pdwFileType = PMC_FILE;
  789. }
  790. else if (lstrcmpW(pfHeader.szSignature, szPerfAlertSignature) == 0) {
  791. #ifdef _DBG_MSG_PRINT
  792. fprintf(stderr, "\nConverting Alert Settings file \"%ws\" to \n \"%ws\"",
  793. szPerfmonFileName,
  794. szSysmonFileName);
  795. #endif
  796. bSuccess = OpenAlert(szPerfmonFileName, hInFile, fOutFile, szSingleObjectName);
  797. * pdwFileType = PMA_FILE;
  798. }
  799. else if (lstrcmpW(pfHeader.szSignature, szPerfLogSignature) == 0) {
  800. #ifdef _DBG_MSG_PRINT
  801. fprintf(stderr, "\nConverting Log Settings file \"%ws\" to \n \"%ws\"",
  802. szPerfmonFileName,
  803. szSysmonFileName);
  804. #endif
  805. bSuccess = OpenLog(szPerfmonFileName, hInFile, fOutFile, szSingleObjectName);
  806. * pdwFileType = PML_FILE;
  807. }
  808. else if (lstrcmpW(pfHeader.szSignature, szPerfReportSignature) == 0) {
  809. #ifdef _DBG_MSG_PRINT
  810. fprintf(stderr, "\nConverting Report Settings file \"%ws\" to \n \"%ws\"",
  811. szPerfmonFileName,
  812. szSysmonFileName);
  813. #endif
  814. bSuccess = OpenReport(hInFile, fOutFile, szSingleObjectName);
  815. * pdwFileType = PMR_FILE;
  816. }
  817. else if (lstrcmpW(pfHeader.szSignature, szPerfWorkspaceSignature) == 0) {
  818. #ifdef _DBG_MSG_PRINT
  819. fprintf(stderr, "\nConverting Workspace Settings file \"%ws\" to \n \"%ws\"",
  820. szPerfmonFileName,
  821. szSysmonFileName);
  822. #endif
  823. bSuccess = OpenWorkspace(szPerfmonFileName, hInFile, fOutFile);
  824. * pdwFileType = PMW_FILE;
  825. }
  826. else {
  827. // not a valid signature
  828. bSuccess = FALSE;
  829. }
  830. fwprintf(fOutFile, szHtmlFooter);
  831. fclose(fOutFile);
  832. }
  833. else {
  834. // not a valid file open
  835. bSuccess = FALSE;
  836. }
  837. }
  838. }
  839. if (hInFile != INVALID_HANDLE_VALUE) CloseHandle(hInFile);
  840. return bSuccess;
  841. }
  842. BOOL
  843. MakeTempFileName (
  844. IN LPCWSTR wszRoot,
  845. IN LPWSTR wszTempFilename,
  846. IN DWORD dwTempNameLen
  847. )
  848. {
  849. FILETIME ft;
  850. DWORD dwReturn = 0;
  851. HRESULT hr = S_OK;
  852. WCHAR wszLocalFilename[MAX_PATH];
  853. GetSystemTimeAsFileTime(& ft);
  854. ZeroMemory(wszLocalFilename, MAX_PATH * sizeof(WCHAR));
  855. hr = StringCchPrintfW(wszLocalFilename,
  856. MAX_PATH,
  857. (LPCWSTR) L"%%temp%%\\%s_%8.8x%8.8x.htm",
  858. (wszRoot != NULL ? wszRoot : (LPCWSTR) L"LodCtr"),
  859. ft.dwHighDateTime,
  860. ft.dwLowDateTime);
  861. if (hr == S_OK) {
  862. // expand env. vars
  863. dwReturn = ExpandEnvironmentStringsW(wszLocalFilename, wszTempFilename, dwTempNameLen);
  864. }
  865. return (BOOL)(dwReturn > 0);
  866. }
  867. BOOL
  868. IsPerfmonFile(
  869. IN LPWSTR szFileName
  870. )
  871. {
  872. LPWSTR szResult = NULL;
  873. _wcslwr(szFileName);
  874. if (szResult == NULL) szResult = wcsstr(szFileName, (LPCWSTR) L".pmc"); // test for chart settings file
  875. if (szResult == NULL) szResult = wcsstr(szFileName, (LPCWSTR) L".pmr"); // test for report settings file
  876. if (szResult == NULL) szResult = wcsstr(szFileName, (LPCWSTR) L".pma"); // test for alert settings file
  877. if (szResult == NULL) szResult = wcsstr(szFileName, (LPCWSTR) L".pml"); // test for log settings file
  878. if (szResult == NULL) szResult = wcsstr(szFileName, (LPCWSTR) L".pmw"); // test for workspace file
  879. return (szResult == NULL) ? (FALSE) : (TRUE);
  880. }
  881. int
  882. __cdecl wmain(
  883. int argc,
  884. wchar_t * argv[]
  885. )
  886. {
  887. WCHAR szCommandLine[MAXSTR];
  888. WCHAR szArgList[MAX_ARG_STR];
  889. WCHAR szTempFileName[MAXSTR];
  890. WCHAR szTempArg[MAXSTR];
  891. LPWSTR szArgFileName;
  892. int iThisArg;
  893. DWORD dwArgListLen;
  894. DWORD dwArgLen;
  895. STARTUPINFOW startInfo;
  896. PROCESS_INFORMATION processInfo;
  897. DWORD dwReturnValue = ERROR_SUCCESS;
  898. BOOL bSuccess = TRUE;
  899. DWORD dwPmFileType = 0;
  900. BOOL bPerfmonFileMade = FALSE;
  901. BOOL bDeleteFileOnExit = TRUE;
  902. ZeroMemory(& startInfo, sizeof(STARTUPINFOW));
  903. ZeroMemory(& processInfo, sizeof(PROCESS_INFORMATION));
  904. ZeroMemory(szCommandLine, MAXSTR * sizeof(WCHAR));
  905. ZeroMemory(szArgList, MAX_ARG_STR * sizeof(WCHAR));
  906. ZeroMemory(szTempFileName, MAXSTR * sizeof(WCHAR));
  907. ZeroMemory(szTempArg, MAXSTR * sizeof(WCHAR));
  908. startInfo.cb = sizeof(startInfo);
  909. startInfo.dwFlags = STARTF_USESTDHANDLES;
  910. startInfo.wShowWindow = SW_SHOWDEFAULT;
  911. dwArgListLen = ExpandEnvironmentStringsW(szMmcExeCmd, szCommandLine, MAXSTR);
  912. dwArgListLen = ExpandEnvironmentStringsW(szMmcExeArg, szArgList, MAX_ARG_STR);
  913. szArgList[MAX_ARG_STR - 1] = UNICODE_NULL;
  914. if (argc >= 2) {
  915. for (iThisArg = 1; iThisArg < argc; iThisArg ++) {
  916. if (IsPerfmonFile(argv[iThisArg])) {
  917. if (! bPerfmonFileMade) {
  918. if (szTempFileName[0] == UNICODE_NULL) {
  919. // if there's no filename, then make one
  920. MakeTempFileName((LPCWSTR) L"PMSettings", szTempFileName, MAXSTR);
  921. }
  922. bSuccess = ConvertPerfmonFile(argv[iThisArg], szTempFileName, & dwPmFileType);
  923. if (bSuccess) {
  924. ZeroMemory(szTempArg, MAXSTR * sizeof(WCHAR));
  925. StringCchPrintfW(szTempArg,
  926. MAXSTR,
  927. szMmcExeSetsArg,
  928. (PML_FILE == dwPmFileType || PMA_FILE == dwPmFileType)
  929. ? szMmcExeSetsLogOpt : szEmpty,
  930. szTempFileName);
  931. bPerfmonFileMade = TRUE;
  932. }
  933. else {
  934. // ignore this parameter
  935. szTempArg[0] = UNICODE_NULL;
  936. szTempArg[1] = UNICODE_NULL;
  937. }
  938. }
  939. }
  940. else if (lstrcmpiW(argv[iThisArg], (LPCWSTR) L"/WMI") == 0) {
  941. // this is a special switch
  942. ZeroMemory(szTempArg, MAXSTR * sizeof(WCHAR));
  943. StringCchCopyW(szTempArg, MAXSTR, (LPCWSTR) L"/SYSMON_WMI");
  944. }
  945. else if ( (argv[iThisArg][0] == L'/')
  946. && ((argv[iThisArg][1] == L'H') || (argv[iThisArg][1] == L'h'))
  947. && ((argv[iThisArg][2] == L'T') || (argv[iThisArg][2] == L't'))
  948. && ((argv[iThisArg][3] == L'M') || (argv[iThisArg][3] == L'm'))
  949. && ((argv[iThisArg][4] == L'L') || (argv[iThisArg][4] == L'l'))
  950. && ((argv[iThisArg][5] == L'F') || (argv[iThisArg][5] == L'f'))
  951. && ((argv[iThisArg][6] == L'I') || (argv[iThisArg][6] == L'i'))
  952. && ((argv[iThisArg][7] == L'L') || (argv[iThisArg][7] == L'l'))
  953. && ((argv[iThisArg][8] == L'E') || (argv[iThisArg][8] == L'e'))
  954. && (argv[iThisArg][9] == L':')) {
  955. szArgFileName = &argv[iThisArg][10];
  956. if (bPerfmonFileMade) {
  957. // then copy the file from the temp to the save file
  958. CopyFileW(szTempFileName, szArgFileName, FALSE);
  959. }
  960. else {
  961. // else set the perfmon file name to the one specified in the command line
  962. ZeroMemory(szTempArg, MAXSTR * sizeof(WCHAR));
  963. StringCchCopyW(szTempFileName, MAXSTR, szArgFileName);
  964. bDeleteFileOnExit = FALSE;
  965. }
  966. }
  967. else {
  968. // just copy the arg
  969. ZeroMemory(szTempArg, MAXSTR * sizeof(WCHAR));
  970. StringCchCopyW(szTempArg, MAXSTR, argv[iThisArg]);
  971. szTempArg[MAXSTR - 1] = UNICODE_NULL;
  972. }
  973. dwArgLen = lstrlenW(szTempArg) + 1;
  974. if ((dwArgLen + dwArgListLen) < MAX_ARG_STR) {
  975. szArgList[dwArgListLen - 1] = L' '; // add in delimiter
  976. StringCchCopyW(& szArgList[dwArgListLen],
  977. MAX_ARG_STR - dwArgListLen - 1,
  978. szTempArg);
  979. dwArgListLen += dwArgLen;
  980. }
  981. else {
  982. // no more room in the arg list buffer so bail
  983. break;
  984. }
  985. }
  986. }
  987. if (bSuccess) {
  988. #ifdef _DBG_MSG_PRINT
  989. fwprintf(stderr, (LPCWSTR) L"\nStarting \"%ws\" \"%ws\"", szCommandLine, szArgList);
  990. #endif
  991. bSuccess = CreateProcessW(
  992. szCommandLine,
  993. szArgList,
  994. NULL,
  995. NULL,
  996. FALSE,
  997. DETACHED_PROCESS,
  998. NULL,
  999. NULL,
  1000. & startInfo,
  1001. & processInfo);
  1002. if (! bSuccess) {
  1003. dwReturnValue = GetLastError();
  1004. }
  1005. else {
  1006. Sleep(5000); // wait for things to get going
  1007. CloseHandle(processInfo.hProcess);
  1008. CloseHandle(processInfo.hThread);
  1009. }
  1010. #ifndef _DBG_MSG_PRINT
  1011. if (bPerfmonFileMade && bDeleteFileOnExit) {
  1012. DeleteFileW(szTempFileName);
  1013. }
  1014. #endif
  1015. }
  1016. return (int) dwReturnValue;
  1017. }