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.

225 lines
4.9 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: viewlog.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3/25/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "dbg.h"
  20. #include "macros.h"
  21. #include "..\inc\common.hxx"
  22. #include "..\inc\resource.h"
  23. #include "..\inc\misc.hxx"
  24. #include "resource.h"
  25. extern HINSTANCE g_hInstance;
  26. LRESULT
  27. OnViewLog_RegGetValue(
  28. HKEY hKeyMachine,
  29. LPCTSTR pszValueName,
  30. LPTSTR pszValueStr);
  31. #define SUBKEY_LOGPATH TEXT("LogPath")
  32. #ifdef UNICODE
  33. #define FMT_TSTR "%S"
  34. #else
  35. #define FMT_TSTR "%s"
  36. #endif
  37. //____________________________________________________________________________
  38. //
  39. // Function: OnViewLog
  40. //
  41. // Synopsis: Open the job sheduler log.
  42. //
  43. // Arguments: [hwndOwner] -- IN
  44. //
  45. // Returns: void
  46. //
  47. // History: 3/25/1996 RaviR Created
  48. //
  49. //____________________________________________________________________________
  50. void
  51. OnViewLog(
  52. LPTSTR lpMachineName,
  53. HWND hwndOwner)
  54. {
  55. TCHAR tszLogPath[MAX_PATH + 1];
  56. ULONG ulTemp;
  57. HKEY hKeyMachine = HKEY_LOCAL_MACHINE;
  58. LRESULT lr = 0;
  59. if (lpMachineName != NULL)
  60. {
  61. lr = RegConnectRegistry(lpMachineName, HKEY_LOCAL_MACHINE,
  62. &hKeyMachine);
  63. if (lr != ERROR_SUCCESS)
  64. {
  65. CHECK_LASTERROR(lr);
  66. return;
  67. }
  68. }
  69. //
  70. // Get the log file name.
  71. //
  72. lr = OnViewLog_RegGetValue(hKeyMachine, SUBKEY_LOGPATH, tszLogPath);
  73. RegCloseKey(hKeyMachine);
  74. if (lr == ERROR_SUCCESS)
  75. {
  76. if (lpMachineName != NULL)
  77. {
  78. // If path is drive based convert it to share based.
  79. if (s_isDriveLetter(tszLogPath[0]) && tszLogPath[1] == TEXT(':'))
  80. {
  81. TCHAR tszBuf[MAX_PATH + 1];
  82. lstrcpy(tszBuf, tszLogPath);
  83. tszBuf[1] = TEXT('$');
  84. if (lpMachineName[0] == TEXT('\\'))
  85. {
  86. Win4Assert(lpMachineName[1] == TEXT('\\'));
  87. tszLogPath[0] = TEXT('\0');
  88. }
  89. else
  90. {
  91. lstrcpy(tszLogPath, TEXT("\\\\"));
  92. }
  93. lstrcat(tszLogPath, lpMachineName);
  94. lstrcat(tszLogPath, TEXT("\\"));
  95. lstrcat(tszLogPath, tszBuf);
  96. DEBUG_OUT((DEB_USER1, "Viewing log -> " FMT_TSTR "\n", tszLogPath));
  97. }
  98. }
  99. }
  100. else
  101. {
  102. if (lpMachineName == NULL)
  103. {
  104. CHECK_LASTERROR(lr);
  105. return;
  106. }
  107. ulTemp = ExpandEnvironmentStrings(TSZ_LOG_NAME_DEFAULT,
  108. tszLogPath, MAX_PATH);
  109. if (ulTemp == 0)
  110. {
  111. DEBUG_OUT_LASTERROR;
  112. return;
  113. }
  114. if (ulTemp > MAX_PATH)
  115. {
  116. CHECK_LASTERROR(ERROR_INSUFFICIENT_BUFFER);
  117. return;
  118. }
  119. }
  120. //
  121. // Create a process to open the log.
  122. //
  123. HINSTANCE hinst = ShellExecute(0, TEXT("open"), tszLogPath, 0, 0, SW_SHOW);
  124. if ((INT_PTR)hinst <= 32)
  125. {
  126. DEBUG_OUT((DEB_ERROR, " returned %dL\n", hinst));
  127. }
  128. }
  129. //____________________________________________________________________________
  130. //
  131. // Function: OnViewLog_RegGetValue
  132. //
  133. // Synopsis: S
  134. //
  135. // Arguments: [pszValueName] -- IN
  136. // [pszValueStr] -- IN
  137. //
  138. // Returns: LRESULT
  139. //
  140. // History: 3/25/1996 RaviR Created
  141. //
  142. //____________________________________________________________________________
  143. LRESULT
  144. OnViewLog_RegGetValue(
  145. HKEY hKeyMachine,
  146. LPCTSTR pszValueName,
  147. LPTSTR pszValueStr)
  148. {
  149. HKEY hKey = NULL;
  150. LRESULT lr = ERROR_SUCCESS;
  151. //
  152. // Read the log path and maximum size from the registry.
  153. //
  154. lr = RegOpenKeyEx(hKeyMachine, SCH_AGENT_KEY, 0, KEY_READ, &hKey);
  155. if (lr == ERROR_SUCCESS)
  156. {
  157. TCHAR szBuff[MAX_PATH];
  158. DWORD dwTemp = MAX_PATH * sizeof(TCHAR);
  159. DWORD dwType;
  160. lr = RegQueryValueEx(hKey, pszValueName, 0, &dwType,
  161. (UCHAR *)szBuff, &dwTemp);
  162. if (lr == ERROR_SUCCESS)
  163. {
  164. switch (dwType)
  165. {
  166. case REG_SZ:
  167. CopyMemory(pszValueStr, szBuff, dwTemp);
  168. break;
  169. case REG_EXPAND_SZ:
  170. dwTemp = ExpandEnvironmentStrings(szBuff, pszValueStr,
  171. MAX_PATH);
  172. if (dwTemp > MAX_PATH)
  173. {
  174. lr = ERROR_INSUFFICIENT_BUFFER;
  175. }
  176. break;
  177. }
  178. }
  179. RegCloseKey(hKey);
  180. }
  181. return lr;
  182. }