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.

343 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Scheduling Agent Service
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  7. //
  8. // File: common.hxx
  9. //
  10. // Contents: Common globals.
  11. //
  12. // Classes: None.
  13. //
  14. // Functions: InitGlobals & FreeGlobals
  15. //
  16. // History: 08-Sep-95 EricB Created.
  17. // 01-Dec-95 MarkBl Split from util.hxx.
  18. //
  19. //----------------------------------------------------------------------------
  20. #ifndef __COMMON_HXX__
  21. #define __COMMON_HXX__
  22. //
  23. // Default maximum run time - 3 days (in milliseconds).
  24. //
  25. #define MAX_RUN_TIME_DEFAULT (3 * 24 * 60 * 60 * 1000)
  26. const DWORD RUN_TIME_NO_END = INFINITE;
  27. //
  28. // Default maximum log file size is in KB.
  29. //
  30. #define MAX_LOG_SIZE_DEFAULT (0x20)
  31. //
  32. // Default log name
  33. //
  34. #ifdef UNICODE
  35. #define TSZ_LOG_NAME_DEFAULT L"%WinDir%\\SCHEDLGU.TXT"
  36. #else
  37. #define TSZ_LOG_NAME_DEFAULT "%WinDir%\\SCHEDLOG.TXT"
  38. #endif
  39. //
  40. // DLL that contains the service code and resources if we are
  41. // running in svchost.exe.
  42. //
  43. #define SCH_SERVICE_DLL_NAME TEXT("schedsvc.dll")
  44. //
  45. // Constants
  46. //
  47. const int SCH_BUF_LEN = 80;
  48. const int SCH_SMBUF_LEN = 16;
  49. const int SCH_TIMEBUF_LEN = 32;
  50. const int SCH_DATEBUF_LEN = 64;
  51. const int SCH_MED0BUF_LEN = 32;
  52. const int SCH_MEDBUF_LEN = 64;
  53. const int SCH_BIGBUF_LEN = 256;
  54. const int SCH_XBIGBUF_LEN = 512;
  55. const int SCH_DB_BUFLEN = 256;
  56. #define TSZ_JOB TEXT("job")
  57. #if !defined(UNICODE)
  58. #define WSZ_JOB L"job"
  59. #endif // !defined(UNICODE)
  60. #define TSZ_DOTJOB TEXT(".job")
  61. #define TSZ_AT_JOB_PREFIX TEXT("At")
  62. #define SCH_FOLDER_VALUE TEXT("TasksFolder")
  63. #define SCH_NOTIFYMISS_VALUE TEXT("NotifyOnTaskMiss")
  64. #define SCH_LASTRUN_VALUE TEXT("LastTaskRun")
  65. #define SCH_OLDNAME_VALUE TEXT("OldName")
  66. #define SCH_FIRSTBOOT_VALUE TEXT("FirstBoot")
  67. #define DOTEXE TEXT(".exe")
  68. //
  69. // The main window class and title names are necessary for Sage
  70. // compatibility.
  71. //
  72. #define SCHED_CLASS TEXT("SAGEWINDOWCLASS")
  73. #define SCHED_TITLE TEXT("SYSTEM AGENT COM WINDOW")
  74. #define SCHED_SERVICE_NAME TEXT("Schedule")
  75. #define SCHED_SERVICE_APP_NAME TEXT("mstask.exe")
  76. #define SCHED_SETUP_APP_NAME TEXT("mstinit.exe")
  77. #define SCHED_SETUP_SWITCH TEXT("/setup")
  78. #if defined(_CHICAGO_)
  79. #define SCHED_PRESETUP_SWITCH TEXT("/presetup")
  80. #define SCHED_MEMPHIS_SWITCH TEXT("/memphis")
  81. #endif // defined(_CHICAGO_)
  82. #define SCHED_PREUNSETUP_SWITCH TEXT("/preunsetup")
  83. #define SCHED_LOGON_SWITCH TEXT("/logon")
  84. #define SCHED_FIRSTLOGON_SWITCH TEXT("/firstlogon")
  85. #define SCH_SVC_KEY REGSTR_PATH_SERVICES TEXT("\\") SCHED_SERVICE_NAME
  86. #define SCH_AGENT_KEY TEXT("SOFTWARE\\Microsoft\\SchedulingAgent")
  87. #define SCH_RUN_VALUE TEXT("SchedulingAgent")
  88. #if !defined(_CHICAGO_)
  89. #define REGSTR_WINLOGON TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  90. #define REGSTR_DEFAULT_DOMAIN TEXT("DefaultDomainName")
  91. #endif // !defined(_CHICAGO_)
  92. const WORD SCH_DEFAULT_IDLE_TIME = 10; // 10 minutes.
  93. const WORD SCH_DEFAULT_IDLE_DEADLINE = 60; // 1 hour
  94. #define MAX_SID_SIZE 68 // SIDs are 68 bytes maximum
  95. // (computed from winnt.h SID def)
  96. //
  97. // Private service control codes. Sdk Help says user defined control codes
  98. // should be in the range of 128 to 255. Note that some of these controls
  99. // are used for intra-thread signalling within the service and are not sent
  100. // to the service from outside sources. This is to leverage the functionality
  101. // of the control event.
  102. //
  103. #define SERVICE_CONTROL_USER_LOGON 128
  104. #define SERVICE_CONTROL_TIME_CHANGED 129
  105. #define SERVICE_CONTROL_POWER_SUSPEND 130
  106. #define SERVICE_CONTROL_POWER_SUSPEND_FAILED 131
  107. #define SERVICE_CONTROL_POWER_RESUME 132
  108. #define SERVICE_CONTROL_USER_LOGOFF 133
  109. //
  110. // Service State -- for CurrentState, from winsvc.h
  111. //
  112. // these are defined for NT, define them here for Windows
  113. #if !defined(SERVICE_STOPPED)
  114. #define SERVICE_STOPPED 0x00000001
  115. #endif
  116. #if !defined(SERVICE_START_PENDING)
  117. #define SERVICE_START_PENDING 0x00000002
  118. #endif
  119. #if !defined(SERVICE_STOP_PENDING)
  120. #define SERVICE_STOP_PENDING 0x00000003
  121. #endif
  122. #if !defined(SERVICE_RUNNING)
  123. #define SERVICE_RUNNING 0x00000004
  124. #endif
  125. #if !defined(SERVICE_CONTINUE_PENDING)
  126. #define SERVICE_CONTINUE_PENDING 0x00000005
  127. #endif
  128. #if !defined(SERVICE_PAUSE_PENDING)
  129. #define SERVICE_PAUSE_PENDING 0x00000006
  130. #endif
  131. #if !defined(SERVICE_PAUSED)
  132. #define SERVICE_PAUSED 0x00000007
  133. #endif
  134. //
  135. // System Agent message for idle detection. This is taken from
  136. // \\trango\slm\src\root\dev\inc\sage.h
  137. //
  138. #define WM_SAGE_NOIDLE (WM_USER + 5)
  139. #if defined(_CHICAGO_)
  140. //
  141. // System Agent messages for 16-bit clients. This is taken from
  142. // \\trango\slm\src\root\dev\inc\sage.h
  143. //
  144. #define WM_SAGE_ENABLE (WM_USER + 6)
  145. #define WM_SAGE_DISABLE (WM_USER + 7)
  146. #define WM_SAGE_GETSTATUS (WM_USER + 8)
  147. #define WM_SAGE_ADDTASK (WM_USER + 9)
  148. #define WM_SAGE_REMOVETASK (WM_USER + 10)
  149. #define WM_SAGE_GETTASK (WM_USER + 11)
  150. //
  151. // Message: SCHED_WIN9X_GETSVCSTATE
  152. // wParam: Unused
  153. // lParam: Unused
  154. // Return: dwSchState; // the current service state
  155. //
  156. #define SCHED_WIN9X_GETSVCSTATE (WM_USER + 200)
  157. //
  158. // Message: SCHED_WIN9X_STOPSVC
  159. // wParam: Unused
  160. // lParam: Unused
  161. // Return: HRESULT
  162. //
  163. #define SCHED_WIN9X_STOPSVC (WM_USER + 201)
  164. //
  165. // Message: SCHED_WIN9X_PAUSESVC
  166. // wParam: Unused
  167. // lParam: Unused
  168. // Return: HRESULT
  169. //
  170. #define SCHED_WIN9X_PAUSESVC (WM_USER + 202)
  171. //
  172. // Message: SCHED_WIN9X_CONTINUESVC
  173. // wParam: Unused
  174. // lParam: Unused
  175. // Return: HRESULT
  176. //
  177. #define SCHED_WIN9X_CONTINUESVC (WM_USER + 203)
  178. //
  179. // Message: WM_SCHED_WIN9X_USER_LOGON
  180. // wParam: Unused
  181. // lParam: Unused
  182. // Return: Unused
  183. //
  184. #define WM_SCHED_WIN9X_USER_LOGON (WM_USER + 204)
  185. #endif // _CHICAGO_
  186. //
  187. // Messages from the service main thread to the message-pump thread
  188. // to call functions in msidle.dll
  189. //
  190. //
  191. // Message: WM_SCHED_SetNextIdleNotification
  192. // wParam: wIdleWait
  193. // lParam: Unused
  194. // Return: Unused
  195. //
  196. #define WM_SCHED_SetNextIdleNotification (WM_USER + 210)
  197. //
  198. // Message: WM_SCHED_SetIdleLossNotification
  199. // wParam: Unused
  200. // lParam: Unused
  201. // Return: Unused
  202. //
  203. #define WM_SCHED_SetIdleLossNotification (WM_USER + 211)
  204. //
  205. // Globals
  206. //
  207. extern HINSTANCE g_hInstance;
  208. extern TCHAR g_tszSrvcName[];
  209. extern BOOL g_fNotifyMiss;
  210. extern DWORD g_WakeCountSlot;
  211. #if !defined(_CHICAGO_)
  212. extern WCHAR g_wszAtJobSearchPath[];
  213. #endif // !defined(_CHICAGO_)
  214. //
  215. // Tasks folder structure definition.
  216. //
  217. typedef enum _FILESYSTEMTYPE {
  218. FILESYSTEM_FAT,
  219. FILESYSTEM_NTFS
  220. } FILESYSTEMTYPE;
  221. typedef struct _TasksFolderInfo {
  222. LPTSTR ptszPath;
  223. FILESYSTEMTYPE FileSystemType;
  224. } TasksFolderInfo;
  225. //
  226. // Registry settings for the scheduler (and more).
  227. //
  228. extern TasksFolderInfo g_TasksFolderInfo;
  229. //
  230. // BUGBUG: global __int64 initialization is not working without the CRT.
  231. // BUG # 37752.
  232. //
  233. extern __int64 FILETIMES_PER_DAY;
  234. //
  235. // Global data initialization/cleanup routines.
  236. //
  237. HRESULT
  238. InitGlobals(void);
  239. void
  240. FreeGlobals(void);
  241. //
  242. // Routines for reading/writing other registry data.
  243. //
  244. BOOL ReadLastTaskRun(SYSTEMTIME * pstLastRun);
  245. void WriteLastTaskRun(const SYSTEMTIME * pstLastRun);
  246. #if !defined(_CHICAGO_)
  247. //
  248. // Retrieves the file system type, either FAT or NTFS, of the path indicated.
  249. // This function initializes the FileSystemType field of g_TasksFolderInfo.
  250. //
  251. HRESULT
  252. GetFileSystemTypeFromPath(
  253. LPCWSTR pwszPath,
  254. FILESYSTEMTYPE * pFileSystemType);
  255. HRESULT
  256. ComputeJobSignature(
  257. LPCWSTR pwszFileName,
  258. LPBYTE pSignature
  259. );
  260. #endif // !defined(_CHICAGO_)
  261. //
  262. // Routines in path.cxx for working with file & path names
  263. //
  264. #define MAX_PATH_VALUE 1024
  265. VOID
  266. StripLeadTrailSpace(LPTSTR ptsz);
  267. VOID
  268. GetAppPathInfo(
  269. LPCTSTR ptszFilename,
  270. LPTSTR ptszAppPathDefault,
  271. ULONG cchDefaultBuf,
  272. LPTSTR ptszAppPathVar,
  273. ULONG cchPathVarBuf);
  274. BOOL
  275. ProcessApplicationName(LPTSTR ptszFilename, LPCTSTR tszWorkingDir);
  276. BOOL
  277. IsLocalFilename(LPCTSTR tszFilename);
  278. VOID
  279. DeleteQuotes(LPTSTR ptsz);
  280. VOID
  281. AddQuotes(LPTSTR ptsz, ULONG cchBuf);
  282. BOOL
  283. FileExists(LPTSTR ptszFileName);
  284. #endif // __COMMON_HXX__