Basic Univers
#CLSCTX_INPROC_SERVER = 1
#COR_E_FILENOTFOUND = $80070002
#TASK_TRIGGER_FLAG_HAS_END_DATE = $1
Enumeration 0
#TASK_TIME_TRIGGER_ONCE = 0
#TASK_TIME_TRIGGER_DAILY = 1
#TASK_TIME_TRIGGER_WEEKLY = 2
#TASK_TIME_TRIGGER_MONTHLYDATE = 3
#TASK_TIME_TRIGGER_MONTHLYDOW = 4
#TASK_EVENT_TRIGGER_ON_IDLE = 5
#TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6
#TASK_EVENT_TRIGGER_AT_LOGON = 7
EndEnumeration
Interface IEnumWorkItems Extends IUnknown
Next(a.l, b.l, c.l)
Skip(a.l)
Reset()
Clone(a.l)
EndInterface
Interface IProvideTaskPage Extends IUnknown
GetPage(tpType.l, fPersistChanges.l, phPage.l)
EndInterface
Interface IScheduledWorkItem Extends IUnknown
CreateTrigger(piNewTrigger.l, ppTrigger.l)
DeleteTrigger(iTrigger.l)
GetTriggerCount(plCount.l)
GetTrigger(iTrigger.l, ppTrigger.l)
GetTriggerString(iTrigger.l, ppwszTrigger.l)
GetRunTimes(pstBegin.l, pstEnd.l, pCount.l, rgstTaskTimes.l)
GetNextRunTime(pstNextRun.l)
SetIdleWait(wIdleMinutes.l, wDeadlineMinutes.l)
GetIdleWait(pwIdleMinutes.l, pwDeadlineMinutes.l)
Run()
Terminate()
EditWorkItem(hParent.l, dwReserved.l)
GetMostRecentRunTime(pstLastRun.l)
GetStatus(phrStatus.l)
GetExitCode(pdwExitCode.l)
SetComment(pwszComment.l)
GetComment(ppwszComment.l)
SetCreator(pwszCreator.l)
GetCreator(ppwszCreator.l)
SetWorkItemData(cBytes.l, rgbData.l)
GetWorkItemData(pcBytes.l, ppBytes.l)
SetErrorRetryCount(wRetryCount.l)
GetErrorRetryCount(pwRetryCount.l)
SetErrorRetryInterval(wRetryInterval.l)
GetErrorRetryInterval(pwRetryInterval.l)
SetFlags(dwFlags.l)
GetFlags(pdwFlags.l)
SetAccountInformation(pwszAccountName.l, pwszPassword.l)
GetAccountInformation(ppwszAccountName.l)
EndInterface
Interface ITaskScheduler Extends IUnknown
SetTargetComputer(a.l)
GetTargetComputer(a.l)
Enum(a.l)
Activate(Name.p - bstr, b.l, c.l)
Delete(a.l)
NewWorkItem(Name.p - bstr, b.l, c.l, d.l)
AddWorkItem(a.l, b.l)
IsOfType(a.l, b.l)
EndInterface
Interface ITask Extends IUnknown
CreateTrigger(a.l, b.l)
DeleteTrigger(a.l)
GetTriggerCount(a.l)
GetTrigger(a.l, b.l)
GetTriggerString(a.l, b.l)
GetRunTimes(a.l, b.l, c.l, d.l)
GetNextRunTime(a.l)
SetIdleWait(a.l, b.l)
GetIdleWait(a.l, b.l)
Run()
Terminate()
EditWorkItem(a.l, b.l)
GetMostRecentRunTime(a.l)
GetStatus(a.l)
GetExitCode(a.l)
SetComment(a.l)
GetComment(a.l)
SetCreator(a.l)
GetCreator(a.l)
SetWorkItemData(a.l, b.l)
GetWorkItemData(a.l, b.l)
SetErrorRetryCount(a.l)
GetErrorRetryCount(a.l)
SetErrorRetryInterval(a.l)
GetErrorRetryInterval(a.l)
SetFlags(a.l)
GetFlags(a.l)
SetAccountInformation(a.l, b.l)
GetAccountInformation(a.l)
SetApplicationName(a.l)
GetApplicationName(a.l)
SetParameters(a.l)
GetParameters(a.l)
SetWorkingDirectory(a.l)
GetWorkingDirectory(a.l)
SetPriority(a.l)
GetPriority(a.l)
SetTaskFlags(a.l)
GetTaskFlags(a.l)
SetMaxRunTime(a.l)
GetMaxRunTime(a.l)
EndInterface
Interface ITaskTrigger Extends IUnknown
SetTrigger(pTrigger.l)
GetTrigger(pTrigger.l)
GetTriggerString(ppwszTrigger.l)
EndInterface
Structure DAILY
DaysInterval.w
EndStructure
Structure WEEKLY
WeeksInterval.w
rgfDaysOfTheWeek.w
EndStructure
Structure MONTHLYDATE
rgfDays.l
rgfMonths.w
EndStructure
Structure MONTHLYDOW
wWhichWeek.w
rgfDaysOfTheWeek.w
rgfMonths.w
EndStructure
Structure TRIGGER_TYPE_UNION
StructureUnion
Daily.DAILY
Weekly.WEEKLY
MonthlyDate.MONTHLYDATE
MonthlyDOW.MONTHLYDOW
EndStructureUnion
EndStructure
Structure TASK_TRIGGER
cbTriggerSize.w
Reserved1.w
wBeginYear.w
wBeginMonth.w
wBeginDay.w
wEndYear.w
wEndMonth.w
wEndDay.w
wStartHour.w
wStartMinute.w
MinutesDuration.l
MinutesInterval.l
rgFlags.l
TriggerType.l
Type.TRIGGER_TYPE_UNION
Reserved2.w
wRandomMinutesInterval.w
EndStructure
Macro FAILED(hr)
hr <> #S_OK)
EndMacro
Macro SUCCEEDED(hr)
hr = #S_OK)
EndMacro
Procedure.l main()
Protected hr.l
Protected pITS.ITaskScheduler
Protected pITask.ITask
Protected pITaskTrigger.ITaskTrigger
Protected piNewTrigger.w
Protected pTrigger.TASK_TRIGGER
Protected pIPersistFile.IPersistFile
hr = CoInitialize_(#Null)
If(SUCCEEDED(hr))
hr = CoCreateInstance_(?CLSID_CTaskScheduler, #Null, #CLSCTX_INPROC_SERVER, ?IID_ITaskScheduler, @pITS)
If(FAILED(hr))
CoUninitialize_()
ProcedureReturn 1
EndIf
Else
ProcedureReturn 1
EndIf
hr = pITS\Activate("Task Example", ?IID_ITask, @pITask)
pITS\Release()
If(FAILED(hr))
Debug "Failed calling ITaskScheduler::Activate: error = 0x" + Hex(hr)
CoUninitialize_()
ProcedureReturn 1
EndIf
hr = pITask\CreateTrigger(@piNewTrigger, @pITaskTrigger)
If(FAILED(hr))
Debug "Failed calling ITask::CreateTrigger: error = 0x" + Hex(hr)
pITask\Release()
CoUninitialize_()
ProcedureReturn 1
EndIf
Protected Trigger.ITaskTrigger
Protected TaskTrigger.TASK_TRIGGER
If pITask\GetTrigger(Num, @Trigger) = #S_OK
TaskTrigger\cbTriggerSize = SizeOf(TASK_TRIGGER)
Debug SizeOf(TASK_TRIGGER)
If Trigger\GetTrigger(@TaskTrigger) = #S_OK
Debug ""
Debug "----- TRIGGER -----Start"
Debug TaskTrigger\cbTriggerSize.w
Debug TaskTrigger\Reserved1.w
Debug TaskTrigger\wBeginYear.w
Debug TaskTrigger\wBeginMonth.w
Debug TaskTrigger\wBeginDay.w
Debug TaskTrigger\wEndYear.w
Debug TaskTrigger\wEndMonth.w
Debug TaskTrigger\wEndDay.w
Debug TaskTrigger\wStartHour.w
Debug TaskTrigger\wStartMinute.w
Debug TaskTrigger\MinutesDuration.l
Debug TaskTrigger\MinutesInterval.l
Debug TaskTrigger\rgFlags.l
Debug TaskTrigger\TriggerType.l
Select TaskTrigger\TriggerType.l
Case #TASK_TIME_TRIGGER_ONCE
Case #TASK_TIME_TRIGGER_DAILY
Debug TaskTrigger\Type\Daily\DaysInterval.w
Case #TASK_TIME_TRIGGER_WEEKLY
Debug TaskTrigger\Type\Weekly\WeeksInterval
Debug TaskTrigger\Type\Weekly\rgfDaysOfTheWeek
Case #TASK_TIME_TRIGGER_MONTHLYDATE
Debug TaskTrigger\Type\MonthlyDate\rgfDays
Debug TaskTrigger\Type\MonthlyDate\rgfMonths
Case #TASK_TIME_TRIGGER_MONTHLYDOW
Debug TaskTrigger\Type\MonthlyDOW\wWhichWeek
Debug TaskTrigger\Type\MonthlyDOW\rgfDaysOfTheWeek
Debug TaskTrigger\Type\MonthlyDOW\rgfMonths
Case #TASK_EVENT_TRIGGER_ON_IDLE
Case #TASK_EVENT_TRIGGER_AT_SYSTEMSTART
Case #TASK_EVENT_TRIGGER_AT_LOGON
EndSelect
Debug TaskTrigger\Type.TRIGGER_TYPE_UNION
Debug TaskTrigger\Reserved2.w
Debug TaskTrigger\wRandomMinutesInterval.w
Debug "----- TRIGGER -----End"
Debug ""
EndIf
Else
ProcedureReturn - 1
EndIf
ZeroMemory_(@pTrigger, SizeOf(TASK_TRIGGER))
Debug SizeOf(TASK_TRIGGER)
pTrigger\wBeginDay = 1
pTrigger\wBeginMonth = 1
pTrigger\wBeginYear = 1999
pTrigger\cbTriggerSize = SizeOf(TASK_TRIGGER)
pTrigger\wStartHour = 13
pTrigger\TriggerType = #TASK_TIME_TRIGGER_DAILY
pTrigger\Type\Daily\DaysInterval = 1
hr = pITaskTrigger\SetTrigger(@pTrigger)
If(FAILED(hr))
Debug "Failed calling ITaskTrigger::SetTrigger: error = 0x" + Hex(hr)
pITask\Release()
pITaskTrigger\Release()
CoUninitialize_()
ProcedureReturn 1
EndIf
hr = pITask\QueryInterface(?IID_IPersistFile, @pIPersistFile)
hr = pIPersistFile\Save(#Null, #True)
If(FAILED(hr))
Debug "Failed calling IPersistFile::Save: error = 0x" + Hex(hr)
pITask\Release()
pITaskTrigger\Release()
pIPersistFile\Release()
CoUninitialize_()
ProcedureReturn 1
EndIf
Debug "The trigger was created and IPersistFile::Save was"
Debug "called to save the new trigger to disk."
pITask\Release()
pITaskTrigger\Release()
pIPersistFile\Release()
CoUninitialize_()
ProcedureReturn 0
EndProcedure
Debug main()
DataSection
CLSID_CTask :
Data.l $148BD520
Data.w $A2AB, $11CE
Data.b $B1, $1F, $00, $AA, $00, $53, $05, $03
CLSID_CTaskScheduler:
Data.l $148BD52A
Data.w $A2AB, $11CE
Data.b $B1, $1F, $00, $AA, $00, $53, $05, $03
IID_IPersistFile:
Data.l $0000010B
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_ITask:
Data.l $148BD524
Data.w $A2AB, $11CE
Data.b $B1, $1F, $00, $AA, $00, $53, $05, $03
IID_ITaskScheduler:
Data.l $148BD527
Data.w $A2AB, $11CE
Data.b $B1, $1F, $00, $AA, $00, $53, $05, $03
EndDataSection