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.

284 lines
7.2 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. #define TSZ_LOG_NAME_DEFAULT L"%SystemRoot%\\Tasks\\SCHEDLGU.TXT"
  35. //
  36. // DLL that contains the service code and resources if we are
  37. // running in svchost.exe.
  38. //
  39. #define SCH_SERVICE_DLL_NAME TEXT("schedsvc.dll")
  40. //
  41. // Constants
  42. //
  43. const int SCH_BUF_LEN = 80;
  44. const int SCH_SMBUF_LEN = 16;
  45. const int SCH_TIMEBUF_LEN = 32;
  46. const int SCH_DATEBUF_LEN = 64;
  47. const int SCH_MED0BUF_LEN = 32;
  48. const int SCH_MEDBUF_LEN = 64;
  49. const int SCH_BIGBUF_LEN = 256;
  50. const int SCH_XBIGBUF_LEN = 512;
  51. const int SCH_DB_BUFLEN = 256;
  52. #define TSZ_JOB TEXT("job")
  53. #define TSZ_DOTJOB TEXT(".job")
  54. #define TSZ_AT_JOB_PREFIX TEXT("At")
  55. #define SCH_FOLDER_VALUE TEXT("TasksFolder")
  56. #define SCH_NOTIFYMISS_VALUE TEXT("NotifyOnTaskMiss")
  57. #define SCH_LASTRUN_VALUE TEXT("LastTaskRun")
  58. #define SCH_OLDNAME_VALUE TEXT("OldName")
  59. #define SCH_FIRSTBOOT_VALUE TEXT("FirstBoot")
  60. #define DOTEXE TEXT(".exe")
  61. //
  62. // The main window class and title names are necessary for Sage
  63. // compatibility.
  64. //
  65. #define SCHED_CLASS TEXT("SAGEWINDOWCLASS")
  66. #define SCHED_TITLE TEXT("SYSTEM AGENT COM WINDOW")
  67. #define SCHED_SERVICE_NAME TEXT("Schedule")
  68. #define SCHED_SETUP_APP_NAME TEXT("mstinit.exe")
  69. #define SCH_SVC_KEY REGSTR_PATH_SERVICES TEXT("\\") SCHED_SERVICE_NAME
  70. #define SCH_AGENT_KEY TEXT("SOFTWARE\\Microsoft\\SchedulingAgent")
  71. #define SCH_RUN_VALUE TEXT("SchedulingAgent")
  72. #define REGSTR_WINLOGON TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  73. #define REGSTR_DEFAULT_DOMAIN TEXT("DefaultDomainName")
  74. const WORD SCH_DEFAULT_IDLE_TIME = 10; // 10 minutes.
  75. const WORD SCH_DEFAULT_IDLE_DEADLINE = 60; // 1 hour
  76. #define MAX_SID_SIZE 68 // SIDs are 68 bytes maximum
  77. // (computed from winnt.h SID def)
  78. //
  79. // Private service control codes. Sdk Help says user defined control codes
  80. // should be in the range of 128 to 255. Note that some of these controls
  81. // are used for intra-thread signalling within the service and are not sent
  82. // to the service from outside sources. This is to leverage the functionality
  83. // of the control event.
  84. //
  85. #define SERVICE_CONTROL_USER_LOGON 128
  86. #define SERVICE_CONTROL_TIME_CHANGED 129
  87. #define SERVICE_CONTROL_POWER_SUSPEND 130
  88. #define SERVICE_CONTROL_POWER_SUSPEND_FAILED 131
  89. #define SERVICE_CONTROL_POWER_RESUME 132
  90. #define SERVICE_CONTROL_USER_LOGOFF 133
  91. //
  92. // Service State -- for CurrentState, from winsvc.h
  93. //
  94. // these are defined for NT, define them here for Windows
  95. #if !defined(SERVICE_STOPPED)
  96. #define SERVICE_STOPPED 0x00000001
  97. #endif
  98. #if !defined(SERVICE_START_PENDING)
  99. #define SERVICE_START_PENDING 0x00000002
  100. #endif
  101. #if !defined(SERVICE_STOP_PENDING)
  102. #define SERVICE_STOP_PENDING 0x00000003
  103. #endif
  104. #if !defined(SERVICE_RUNNING)
  105. #define SERVICE_RUNNING 0x00000004
  106. #endif
  107. #if !defined(SERVICE_CONTINUE_PENDING)
  108. #define SERVICE_CONTINUE_PENDING 0x00000005
  109. #endif
  110. #if !defined(SERVICE_PAUSE_PENDING)
  111. #define SERVICE_PAUSE_PENDING 0x00000006
  112. #endif
  113. #if !defined(SERVICE_PAUSED)
  114. #define SERVICE_PAUSED 0x00000007
  115. #endif
  116. //
  117. // Messages from the service main thread to the message-pump thread
  118. // to call functions in msidle.dll
  119. //
  120. //
  121. // Message: WM_SCHED_SetNextIdleNotification
  122. // wParam: wIdleWait
  123. // lParam: Unused
  124. // Return: Unused
  125. //
  126. #define WM_SCHED_SetNextIdleNotification (WM_USER + 210)
  127. //
  128. // Message: WM_SCHED_SetIdleLossNotification
  129. // wParam: Unused
  130. // lParam: Unused
  131. // Return: Unused
  132. //
  133. #define WM_SCHED_SetIdleLossNotification (WM_USER + 211)
  134. //
  135. // Globals
  136. //
  137. extern HINSTANCE g_hInstance;
  138. extern TCHAR g_tszSrvcName[];
  139. extern BOOL g_fNotifyMiss;
  140. extern DWORD g_WakeCountSlot;
  141. extern WCHAR g_wszAtJobSearchPath[];
  142. //
  143. // Tasks folder structure definition.
  144. //
  145. typedef enum _FILESYSTEMTYPE {
  146. FILESYSTEM_FAT,
  147. FILESYSTEM_NTFS
  148. } FILESYSTEMTYPE;
  149. typedef struct _TasksFolderInfo {
  150. LPTSTR ptszPath;
  151. FILESYSTEMTYPE FileSystemType;
  152. } TasksFolderInfo;
  153. //
  154. // Registry settings for the scheduler (and more).
  155. //
  156. extern TasksFolderInfo g_TasksFolderInfo;
  157. //
  158. // BUGBUG: global __int64 initialization is not working without the CRT.
  159. // BUG # 37752.
  160. //
  161. extern __int64 FILETIMES_PER_DAY;
  162. //
  163. // Global data initialization/cleanup routines.
  164. //
  165. HRESULT
  166. InitGlobals(void);
  167. void
  168. FreeGlobals(void);
  169. //
  170. // Routines for reading/writing other registry data.
  171. //
  172. BOOL ReadLastTaskRun(SYSTEMTIME * pstLastRun);
  173. void WriteLastTaskRun(const SYSTEMTIME * pstLastRun);
  174. //
  175. // Retrieves the file system type, either FAT or NTFS, of the path indicated.
  176. // This function initializes the FileSystemType field of g_TasksFolderInfo.
  177. //
  178. HRESULT
  179. GetFileSystemTypeFromPath(
  180. LPCWSTR pwszPath,
  181. FILESYSTEMTYPE * pFileSystemType);
  182. HRESULT
  183. GetTasksFolder(
  184. WCHAR** ppwszPath
  185. );
  186. HRESULT
  187. GetNotifyOnTaskMiss(
  188. BOOL* pfNotifyOnTaskMiss
  189. );
  190. HRESULT
  191. EnsureTasksFolderExists(
  192. LPWSTR pwszPath,
  193. BOOL bEnableShellExtension = TRUE
  194. );
  195. //
  196. // Routines in path.cxx for working with file & path names
  197. //
  198. #define MAX_PATH_VALUE 1024
  199. VOID
  200. StripLeadTrailSpace(LPTSTR ptsz);
  201. VOID
  202. GetAppPathInfo(
  203. LPCTSTR ptszFilename,
  204. LPTSTR ptszAppPathDefault,
  205. ULONG cchDefaultBuf,
  206. LPTSTR ptszAppPathVar,
  207. ULONG cchPathVarBuf);
  208. BOOL
  209. ProcessApplicationName(LPTSTR ptszFilename, size_t cchBuff, LPCTSTR tszWorkingDir);
  210. BOOL
  211. IsLocalFilename(LPCTSTR tszFilename);
  212. VOID
  213. DeleteQuotes(LPTSTR ptsz);
  214. VOID
  215. AddQuotes(LPTSTR ptsz, ULONG cchBuf);
  216. BOOL
  217. FileExists(LPTSTR ptszFileName, size_t cchBuff);
  218. //+---------------------------------------------------------------------------
  219. //
  220. // Function: NextChar
  221. //
  222. // Synopsis: Return [wszCur] + 1, or [wszCur] if it points to the end of
  223. // the string.
  224. //
  225. // History: 10-24-96 DavidMun Created
  226. //
  227. //----------------------------------------------------------------------------
  228. inline LPWSTR
  229. NextChar(LPCWSTR wszCur)
  230. {
  231. if (*wszCur)
  232. {
  233. return (LPWSTR) (wszCur + 1);
  234. }
  235. return (LPWSTR) wszCur;
  236. }
  237. #endif // __COMMON_HXX__