It is fairly common knowledge that you can schedule tasks to run periodically (daily, weekly, monthly) using Windows Task Scheduler. But Windows Task Scheduler can do a lot more than that. You can use the "On Event" trigger to run some task after a specific task completes.
Please ensure the below conditions are met before proceeding -
- Task History is disabled - You need to enable all Task History for this to work
- Task Properties > Conditions > "Start the Task only if the computer is on AC power" - If this option is selected and the laptop is not connected to AC power, the task will not be executed.
Once you have verified the above conditions are met, you may proceed with the steps below - ( For the purpose of this post, we will consider a scenario where you would like to run Task B after Task A completes. )
- Select Task B Properties > Triggers > New > Select "On Event Trigger"
- Settings > Custom > New Event Filter
- Select XML Tab > Check "Edit query manually"
- Use one of the below XML XPath Queries based on your requirement
Run Task B based on completion of another Task A
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\TASK_A']]</Select>
</Query>
</QueryList>
Run Task B if any one of the tasks completes
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">
*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\TASK_A1']]
</Select>
</Query>
<Query Id="2" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">
*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\TASK_A2']]
</Select>
</Query>
<Query Id="2" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">
*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\TASK_A3']]
</Select>
</Query>
</QueryList>
Run Task B based on the outcome (return code=0) of Task A
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[EventData[@Name='ActionSuccess'][Data[@Name='TaskName']='\TASK_A' and Data[@Name='ResultCode']=0]]</Select>
</Query>
</QueryList>