Creating a New Trigger
To create a trigger you must use three interfaces. IScheduledWorkItem provides the IScheduledWorkItem::CreateTrigger method for creating the trigger object, ITaskTrigger provides the ITaskTrigger::SetTrigger method for setting the criteria for the trigger, and the COM interface IPersistFile provides a Save method for saving the new trigger to disk.
The following procedure describes how to create a new trigger.
To create a new trigger
- Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This example assumes that the Task Scheduler service is running.)
- Call ITaskScheduler::Activate to get the ITask interface of the task object. (Note that this example gets the "Test Task" task.)
- Call CreateTrigger to create a trigger object. (Note that CreateTrigger is inherited from IScheduledWorkItem.)
- Define a TASK_TRIGGER structure. Note that wBeginDay, wBeginMonth, and wBeginYear members of TASK_TRIGGER must be set to a valid day, month, and year respectively.
- Call ITaskTrigger::SetTrigger to set the trigger criteria.
- Save the task with the new trigger to disk using IPersistFile::Save. (The IPersistFile interface is a standard COM interface supported by the ITask interface.)
- Call Release to release all resources. (Note that Release is an IUnknown method inherited by ITask.)
For a code example of | See |
---|---|
Creating a new trigger for an existing task | C/C++ Code Example: Creating a Task Trigger |
Related topics