jwamstask.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. {******************************************************************************}
  2. { }
  3. { Microsoft Task Scheduler API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: mstask.h, released August 2001. The original Pascal }
  9. { code is: MsTask.pas, released October 2001. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Contributor(s): Sunish Issac (sunish att nettaxi dott com) }
  16. { }
  17. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  18. { }
  19. { You may retrieve the latest version of this file at the Project JEDI }
  20. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  21. { }
  22. { The contents of this file are used with permission, subject to the Mozilla }
  23. { Public License Version 1.1 (the "License"); you may not use this file except }
  24. { in compliance with the License. You may obtain a copy of the License at }
  25. { http://www.mozilla.org/MPL/MPL-1.1.html }
  26. { }
  27. { Software distributed under the License is distributed on an "AS IS" basis, }
  28. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  29. { the specific language governing rights and limitations under the License. }
  30. { }
  31. { Alternatively, the contents of this file may be used under the terms of the }
  32. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  33. { provisions of the LGPL License are applicable instead of those above. }
  34. { If you wish to allow use of your version of this file only under the terms }
  35. { of the LGPL License and not to allow others to use your version of this file }
  36. { under the MPL, indicate your decision by deleting the provisions above and }
  37. { replace them with the notice and other provisions required by the LGPL }
  38. { License. If you do not delete the provisions above, a recipient may use }
  39. { your version of this file under either the MPL or the LGPL License. }
  40. { }
  41. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  42. { }
  43. {******************************************************************************}
  44. unit JwaMsTask;
  45. {$WEAKPACKAGEUNIT}
  46. {$HPPEMIT ''}
  47. {$HPPEMIT '#include "mstask.h"'}
  48. {$HPPEMIT ''}
  49. {$I jediapilib.inc}
  50. interface
  51. uses
  52. JwaWinBase, JwaWinType, JwaPrSht;
  53. const
  54. TASK_SUNDAY = $1;
  55. {$EXTERNALSYM TASK_SUNDAY}
  56. TASK_MONDAY = $2;
  57. {$EXTERNALSYM TASK_MONDAY}
  58. TASK_TUESDAY = $4;
  59. {$EXTERNALSYM TASK_TUESDAY}
  60. TASK_WEDNESDAY = $8;
  61. {$EXTERNALSYM TASK_WEDNESDAY}
  62. TASK_THURSDAY = $10;
  63. {$EXTERNALSYM TASK_THURSDAY}
  64. TASK_FRIDAY = $20;
  65. {$EXTERNALSYM TASK_FRIDAY}
  66. TASK_SATURDAY = $40;
  67. {$EXTERNALSYM TASK_SATURDAY}
  68. TASK_FIRST_WEEK = 1;
  69. {$EXTERNALSYM TASK_FIRST_WEEK}
  70. TASK_SECOND_WEEK = 2;
  71. {$EXTERNALSYM TASK_SECOND_WEEK}
  72. TASK_THIRD_WEEK = 3;
  73. {$EXTERNALSYM TASK_THIRD_WEEK}
  74. TASK_FOURTH_WEEK = 4;
  75. {$EXTERNALSYM TASK_FOURTH_WEEK}
  76. TASK_LAST_WEEK = 5;
  77. {$EXTERNALSYM TASK_LAST_WEEK}
  78. TASK_JANUARY = $1;
  79. {$EXTERNALSYM TASK_JANUARY}
  80. TASK_FEBRUARY = $2;
  81. {$EXTERNALSYM TASK_FEBRUARY}
  82. TASK_MARCH = $4;
  83. {$EXTERNALSYM TASK_MARCH}
  84. TASK_APRIL = $8;
  85. {$EXTERNALSYM TASK_APRIL}
  86. TASK_MAY = $10;
  87. {$EXTERNALSYM TASK_MAY}
  88. TASK_JUNE = $20;
  89. {$EXTERNALSYM TASK_JUNE}
  90. TASK_JULY = $40;
  91. {$EXTERNALSYM TASK_JULY}
  92. TASK_AUGUST = $80;
  93. {$EXTERNALSYM TASK_AUGUST}
  94. TASK_SEPTEMBER = $100;
  95. {$EXTERNALSYM TASK_SEPTEMBER}
  96. TASK_OCTOBER = $200;
  97. {$EXTERNALSYM TASK_OCTOBER}
  98. TASK_NOVEMBER = $400;
  99. {$EXTERNALSYM TASK_NOVEMBER}
  100. TASK_DECEMBER = $800;
  101. {$EXTERNALSYM TASK_DECEMBER}
  102. TASK_FLAG_INTERACTIVE = $1;
  103. {$EXTERNALSYM TASK_FLAG_INTERACTIVE}
  104. TASK_FLAG_DELETE_WHEN_DONE = $2;
  105. {$EXTERNALSYM TASK_FLAG_DELETE_WHEN_DONE}
  106. TASK_FLAG_DISABLED = $4;
  107. {$EXTERNALSYM TASK_FLAG_DISABLED}
  108. TASK_FLAG_START_ONLY_IF_IDLE = $10;
  109. {$EXTERNALSYM TASK_FLAG_START_ONLY_IF_IDLE}
  110. TASK_FLAG_KILL_ON_IDLE_END = $20;
  111. {$EXTERNALSYM TASK_FLAG_KILL_ON_IDLE_END}
  112. TASK_FLAG_DONT_START_IF_ON_BATTERIES = $40;
  113. {$EXTERNALSYM TASK_FLAG_DONT_START_IF_ON_BATTERIES}
  114. TASK_FLAG_KILL_IF_GOING_ON_BATTERIES = $80;
  115. {$EXTERNALSYM TASK_FLAG_KILL_IF_GOING_ON_BATTERIES}
  116. TASK_FLAG_RUN_ONLY_IF_DOCKED = $100;
  117. {$EXTERNALSYM TASK_FLAG_RUN_ONLY_IF_DOCKED}
  118. TASK_FLAG_HIDDEN = $200;
  119. {$EXTERNALSYM TASK_FLAG_HIDDEN}
  120. TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET = $400;
  121. {$EXTERNALSYM TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET}
  122. TASK_FLAG_RESTART_ON_IDLE_RESUME = $800;
  123. {$EXTERNALSYM TASK_FLAG_RESTART_ON_IDLE_RESUME}
  124. TASK_FLAG_SYSTEM_REQUIRED = $1000;
  125. {$EXTERNALSYM TASK_FLAG_SYSTEM_REQUIRED}
  126. TASK_FLAG_RUN_ONLY_IF_LOGGED_ON = $2000;
  127. {$EXTERNALSYM TASK_FLAG_RUN_ONLY_IF_LOGGED_ON}
  128. TASK_TRIGGER_FLAG_HAS_END_DATE = $1;
  129. {$EXTERNALSYM TASK_TRIGGER_FLAG_HAS_END_DATE}
  130. TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = $2;
  131. {$EXTERNALSYM TASK_TRIGGER_FLAG_KILL_AT_DURATION_END}
  132. TASK_TRIGGER_FLAG_DISABLED = $4;
  133. {$EXTERNALSYM TASK_TRIGGER_FLAG_DISABLED}
  134. TASK_MAX_RUN_TIMES = 1440;
  135. {$EXTERNALSYM TASK_MAX_RUN_TIMES}
  136. type
  137. PTaskTriggerType = ^TTaskTriggerType;
  138. _TASK_TRIGGER_TYPE = (
  139. TASK_TIME_TRIGGER_ONCE,
  140. TASK_TIME_TRIGGER_DAILY,
  141. TASK_TIME_TRIGGER_WEEKLY,
  142. TASK_TIME_TRIGGER_MONTHLYDATE,
  143. TASK_TIME_TRIGGER_MONTHLYDOW,
  144. TASK_EVENT_TRIGGER_ON_IDLE,
  145. TASK_EVENT_TRIGGER_AT_SYSTEMSTART,
  146. TASK_EVENT_TRIGGER_AT_LOGON);
  147. TASK_TRIGGER_TYPE = _TASK_TRIGGER_TYPE;
  148. {$EXTERNALSYM TASK_TRIGGER_TYPE}
  149. {$EXTERNALSYM _TASK_TRIGGER_TYPE}
  150. PTASK_TRIGGER_TYPE = ^_TASK_TRIGGER_TYPE;
  151. {$EXTERNALSYM PTASK_TRIGGER_TYPE}
  152. TTaskTriggerType = _TASK_TRIGGER_TYPE;
  153. PDaily = ^TDaily;
  154. _DAILY = record
  155. DaysInterval: WORD;
  156. end;
  157. {$EXTERNALSYM _DAILY}
  158. TDaily = _DAILY;
  159. PWeekly = ^TWeekly;
  160. _WEEKLY = record
  161. WeeksInterval: WORD;
  162. rgfDaysOfTheWeek: WORD;
  163. end;
  164. {$EXTERNALSYM _WEEKLY}
  165. TWeekly = _WEEKLY;
  166. PMonthlyDate = ^TMonthlyDate;
  167. _MONTHLYDATE = record
  168. rgfDays: DWORD;
  169. rgfMonths: WORD;
  170. end;
  171. {$EXTERNALSYM _MONTHLYDATE}
  172. TMonthlyDate = _MONTHLYDATE;
  173. PMonthlyDow = ^TMonthlyDow;
  174. _MONTHLYDOW = record
  175. wWhichWeek: WORD;
  176. rgfDaysOfTheWeek: WORD;
  177. rgfMonths: WORD;
  178. end;
  179. {$EXTERNALSYM _MONTHLYDOW}
  180. TMonthlyDow = _MONTHLYDOW;
  181. PTriggerTypeUnion = ^TTriggerTypeUnion;
  182. _TRIGGER_TYPE_UNION = record
  183. case Integer of
  184. 0: (Daily: TDaily);
  185. 1: (Weekly: TWeekly);
  186. 2: (MonthlyDate: TMonthlyDate);
  187. 3: (MonthlyDOW: TMonthlyDow);
  188. end;
  189. {$EXTERNALSYM _TRIGGER_TYPE_UNION}
  190. TRIGGER_TYPE_UNION = _TRIGGER_TYPE_UNION;
  191. {$EXTERNALSYM TRIGGER_TYPE_UNION}
  192. TTriggerTypeUnion = _TRIGGER_TYPE_UNION;
  193. PTaskTrigger = ^TTaskTrigger;
  194. _TASK_TRIGGER = record
  195. cbTriggerSize: WORD;
  196. Reserved1: WORD;
  197. wBeginYear: WORD;
  198. wBeginMonth: WORD;
  199. wBeginDay: WORD;
  200. wEndYear: WORD;
  201. wEndMonth: WORD;
  202. wEndDay: WORD;
  203. wStartHour: WORD;
  204. wStartMinute: WORD;
  205. MinutesDuration: DWORD;
  206. MinutesInterval: DWORD;
  207. rgFlags: DWORD;
  208. TriggerType: TTaskTriggerType;
  209. Type_: TTriggerTypeUnion;
  210. Reserved2: WORD;
  211. wRandomMinutesInterval: WORD;
  212. end;
  213. {$EXTERNALSYM _TASK_TRIGGER}
  214. TASK_TRIGGER = _TASK_TRIGGER;
  215. {$EXTERNALSYM TASK_TRIGGER}
  216. PTASK_TRIGGER = ^TASK_TRIGGER;
  217. {$EXTERNALSYM PTASK_TRIGGER}
  218. TTaskTrigger = _TASK_TRIGGER;
  219. const
  220. IID_ITaskTrigger: TGUID = '{148BD52B-A2AB-11CE-B11F-00AA00530503}';
  221. {$EXTERNALSYM IID_ITaskTrigger}
  222. // interface ITaskTrigger
  223. type
  224. ITaskTrigger = interface (IUnknown)
  225. ['{148BD52B-A2AB-11CE-B11F-00AA00530503}']
  226. function SetTrigger(const pTrigger: PTaskTrigger): HRESULT; stdcall;
  227. function GetTrigger(pTrigger: PTaskTrigger): HRESULT; stdcall;
  228. function GetTriggerString(var ppwszTrigger: LPWSTR): HRESULT; stdcall;
  229. end;
  230. {$EXTERNALSYM ITaskTrigger}
  231. const
  232. IID_IScheduledWorkItem: TGUID = '{A6B952F0-A4B1-11D0-997D-00AA006887EC}';
  233. {$EXTERNALSYM IID_IScheduledWorkItem}
  234. // interface IScheduledWorkItem
  235. type
  236. IScheduledWorkItem = interface (IUnknown)
  237. ['{A6B952F0-A4B1-11D0-997D-00AA006887EC}']
  238. function CreateTrigger(out piNewTrigger: Word; out ppTrigger: ITaskTrigger): HRESULT; stdcall;
  239. function DeleteTrigger(iTrigger: Word): HRESULT; stdcall;
  240. function GetTriggerCount(out pwCount: Word): HRESULT; stdcall;
  241. function GetTrigger(iTrigger: Word; var ppTrigger: ITaskTrigger): HRESULT; stdcall;
  242. function GetTriggerString(iTrigger: Word; out ppwszTrigger: PWideChar): HRESULT; stdcall;
  243. function GetRunTimes(const pstBegin: LPSYSTEMTIME; const pstEnd: LPSYSTEMTIME;
  244. var pCount: Word; out rgstTaskTimes: LPSYSTEMTIME): HRESULT; stdcall;
  245. function GetNextRunTime(var pstNextRun: SYSTEMTIME): HRESULT; stdcall;
  246. function SetIdleWait(wIdleMinutes: Word; wDeadlineMinutes: Word): HRESULT; stdcall;
  247. function GetIdleWait(out pwIdleMinutes: Word; out pwDeadlineMinutes: Word): HRESULT; stdcall;
  248. function Run: HRESULT; stdcall;
  249. function Terminate: HRESULT; stdcall;
  250. function EditWorkItem(hParent: HWND; dwReserved: DWORD): HRESULT; stdcall;
  251. function GetMostRecentRunTime(out pstLastRun: TSystemTime): HRESULT; stdcall;
  252. function GetStatus(out phrStatus: HRESULT): HRESULT stdcall;
  253. function GetExitCode(out pdwExitCode: DWORD): HRESULT stdcall;
  254. function SetComment(pwszComment: LPCWSTR): HRESULT stdcall;
  255. function GetComment(out ppwszComment: LPWSTR): HRESULT stdcall;
  256. function SetCreator(pwszCreator: LPCWSTR): HRESULT; stdcall;
  257. function GetCreator(out ppwszCreator: LPWSTR): HRESULT; stdcall;
  258. function SetWorkItemData(cbData: Word; var rgbData: Byte): HRESULT; stdcall;
  259. function GetWorkItemData(out pcbData: Word; out prgbData: Byte): HRESULT; stdcall;
  260. function SetErrorRetryCount(wRetryCount: Word): HRESULT; stdcall;
  261. function GetErrorRetryCount(out pwRetryCount: Word): HRESULT; stdcall;
  262. function SetErrorRetryInterval(wRetryInterval: Word): HRESULT; stdcall;
  263. function GetErrorRetryInterval(out pwRetryInterval: Word): HRESULT; stdcall;
  264. function SetFlags(dwFlags: DWORD): HRESULT; stdcall;
  265. function GetFlags(out pdwFlags: DWORD): HRESULT; stdcall;
  266. function SetAccountInformation(pwszAccountName: LPCWSTR; pwszPassword: LPCWSTR): HRESULT; stdcall;
  267. function GetAccountInformation(out ppwszAccountName: LPWSTR): HRESULT; stdcall;
  268. end;
  269. {$EXTERNALSYM IScheduledWorkItem}
  270. const
  271. IID_ITask: TGUID = '{148BD524-A2AB-11CE-B11F-00AA00530503}';
  272. {$EXTERNALSYM IID_ITask}
  273. // interface ITask
  274. type
  275. ITask = interface (IScheduledWorkItem)
  276. ['{148BD524-A2AB-11CE-B11F-00AA00530503}']
  277. function SetApplicationName(pwszApplicationName: LPCWSTR): HRESULT; stdcall;
  278. function GetApplicationName(out ppwszApplicationName: LPWSTR): HRESULT; stdcall;
  279. function SetParameters(pwszParameters: LPCWSTR): HRESULT; stdcall;
  280. function GetParameters(out ppwszParameters: LPWSTR): HRESULT; stdcall;
  281. function SetWorkingDirectory(pwszWorkingDirectory: LPCWSTR): HRESULT; stdcall;
  282. function GetWorkingDirectory(out ppwszWorkingDirectory: LPWSTR): HRESULT; stdcall;
  283. function SetPriority(dwPriority: DWORD): HRESULT; stdcall;
  284. function GetPriority(out pdwPriority: DWORD): HRESULT; stdcall;
  285. function SetTaskFlags(dwFlags: DWORD): HRESULT; stdcall;
  286. function GetTaskFlags(out pdwFlags: DWORD): HRESULT; stdcall;
  287. function SetMaxRunTime(dwMaxRunTimeMS: DWORD): HRESULT; stdcall;
  288. function GetMaxRunTime(out pdwMaxRunTimeMS: DWORD): HRESULT; stdcall;
  289. end;
  290. {$EXTERNALSYM ITask}
  291. const
  292. IID_IEnumWorkItems: TGUID = '{148BD528-A2AB-11CE-B11F-00AA00530503}';
  293. {$EXTERNALSYM IID_IEnumWorkItems}
  294. // interface IEnumWorkItems
  295. type
  296. IEnumWorkItems = interface (IUnknown)
  297. ['{148BD528-A2AB-11CE-B11F-00AA00530503}']
  298. function Next(celt: ULONG; out rgpwszNames: LPLPWSTR; out pceltFetched: ULONG): HRESULT; stdcall;
  299. function Skip(celt: ULONG): HRESULT; stdcall;
  300. function Reset: HRESULT; stdcall;
  301. function Clone(out ppEnumWorkItems: IEnumWorkItems): HRESULT; stdcall;
  302. end;
  303. {$EXTERNALSYM IEnumWorkItems}
  304. const
  305. IID_ITaskScheduler: TGUID = '{148BD527-A2AB-11CE-B11F-00AA00530503}';
  306. {$EXTERNALSYM IID_ITaskScheduler}
  307. // interface ITaskScheduler
  308. type
  309. ITaskScheduler = interface (IUnknown)
  310. ['{148BD527-A2AB-11CE-B11F-00AA00530503}']
  311. function SetTargetComputer(pwszComputer: LPCWSTR): HRESULT; stdcall;
  312. function GetTargetComputer(out ppwszComputer: LPWSTR): HRESULT; stdcall;
  313. function Enum(out ppEnumWorkItems: IEnumWorkItems): HRESULT; stdcall;
  314. function Activate(pwszName: PWideChar; var riid: TGUID; out ppUnk: IUnknown): HRESULT; stdcall;
  315. function Delete(pwszName: LPCWSTR): HRESULT; stdcall;
  316. function NewWorkItem(pwszTaskName: PWideChar; var rclsid: TGUID; var riid: TGUID; out ppUnk: IUnknown): HRESULT; stdcall;
  317. function AddWorkItem(pwszTaskName: LPCWSTR; var pWorkItem: IScheduledWorkItem): HRESULT; stdcall;
  318. function IsOfType(pwszName: LPCWSTR; var riid: TGUID): HRESULT; stdcall;
  319. end;
  320. {$EXTERNALSYM ITaskScheduler}
  321. const
  322. CLSID_CTask: TGuid = '{148BD520-A2AB-11CE-B11F-00AA00530503}';
  323. {$EXTERNALSYM CLSID_CTask}
  324. CLSID_CTaskScheduler: TGuid = '{148BD52A-A2AB-11CE-B11F-00AA00530503}';
  325. {$EXTERNALSYM CLSID_CTaskScheduler}
  326. type
  327. PTaskPage = ^TTaskPage;
  328. _TASKPAGE = (
  329. TASKPAGE_TASK,
  330. TASKPAGE_SCHEDULE,
  331. TASKPAGE_SETTINGS);
  332. {$EXTERNALSYM _TASKPAGE}
  333. TASKPAGE = _TASKPAGE;
  334. {$EXTERNALSYM TASKPAGE}
  335. TTaskPage = _TASKPAGE;
  336. const
  337. IID_IProvideTaskPage: TGuid = '{4086658a-cbbb-11cf-b604-00c04fd8d565}';
  338. {$EXTERNALSYM IID_IProvideTaskPage}
  339. // interface IProvideTaskPage
  340. type
  341. IProvideTaskPage = interface (IUnknown)
  342. ['{4086658A-CBBB-11CF-B604-00C04FD8D565}']
  343. function GetPage(tpType: TTaskPage; fPersistChanges: BOOL; var phPage: HPropSheetPage): HRESULT; stdcall;
  344. end;
  345. {$EXTERNALSYM IProvideTaskPage}
  346. const
  347. ISchedulingAgent = ITaskScheduler;
  348. {$EXTERNALSYM ISchedulingAgent}
  349. IEnumTasks = IEnumWorkItems;
  350. {$EXTERNALSYM IEnumTasks}
  351. //IID_ISchedulingAgent = IID_ITaskScheduler;
  352. IID_ISchedulingAgent: TGUID = '{148BD527-A2AB-11CE-B11F-00AA00530503}';
  353. {$EXTERNALSYM IID_ISchedulingAgent}
  354. //CLSID_CSchedulingAgent = CLSID_CTaskScheduler;
  355. CLSID_CSchedulingAgent: TGuid = '{148BD52A-A2AB-11CE-B11F-00AA00530503}';
  356. {$EXTERNALSYM CLSID_CSchedulingAgent}
  357. //added to use save option without ole2 - not there in original source of mstask.h
  358. {$EXTERNALSYM IID_IPersistFile}
  359. IID_IPersistFile: TGUID = (
  360. D1: $0000010B; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00, $46));
  361. implementation
  362. end.