In Windows Task Scheduler, you can run tasks both on the schedule and after the specific event is registered in the log. (It has been described in the article “Event Triggers in Windows“.) In this article we’ll consider how to automatically start a Scheduler task after the previous task is completed. Let’s take a look at the algorithm to configure dependencies of running Scheduler tasks, which you can customize to meet your needs.
In my case, after one script had been completed I had to start another script from another user account. So these actions could not be united in a single task.
Suppose, we have to start the Pong Scheduler task after the Ping task is completed. When any task is started or completed, the information about this event is registered in the system log. We’ll focus on the event of Ping task completion.
Open Task Scheduler console (Taskschd.msc), locate and select Ping event, and in the bottom panel go to the History tab, which contains the information about all events associated with this task. We need the event with the Event ID 102 (Task completed) which is generated after the task is completed.
Open the detailed event description by going to the Detail tab and enable the XML View of the event. According to the XML data, you can get all details of the event necessary to create a filter. In particular, we need:
Provider-Name: Microsoft-Windows-TaskScheduler
Channel: Microsoft-Windows-TaskScheduler/Operational
TaskName: \ping
When creating a trigger for the Pong task, we have to create a trigger condition for the task to start when the event with the ID 102 appears in the log (Task trigger On an event). But the problem is that EventID 102 appears after any task is completed, not only the Ping task.
However, it is possible to create a more flexible condition for event selection (Custom) if a standard filter does not help to select the event accurately enough. Click New Event Filter:
Create a new event filter by specifying the data from the XML View of the event:
Event source: TaskScheduler
Task category: Task completed
Then go to the XML tab and have a look at the following filter view (XPath):
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[System[Provider[@Name='Microsoft-Windows-TaskScheduler'] and Task = 102]]</Select>
</Query>
</QueryList>
Change the XPath code to the following one, which will filter the log and search for TaskCompleted event for the \ping task:
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[System[Provider[@Name='Microsoft-Windows-TaskScheduler'] and Task = 102]]</Select>
</Query>
</QueryList>
After the event has been added, try to start the ping task. When it is completed, the pong task has to be started immediately.
XPath explanation is displayed below:
14 comments
Don’t work for me on Windows 10 x64
For the section “Change the XPath code” it looks like you pasted the wrong code for us to use.
XPath code example in plain text is wrong when correct code is showed in screenshot.
Of course XML code should reference the actual task name from which completion notification should be triggered:
*[EventData[@Name=’TaskSuccessEvent’][Data[@Name=’TaskName’]=’\ping’]]
You are right, the code is incorrect. This is an old wordpress problem with cutting out some special characters.
I still haven’t fixed it. Sorry.
This xPath code uses wrong kind of quotes. It didn’t work for me. So I used ‘ instead of ’ such in:
*[EventData[@Name=’TaskSuccessEvent’][Data[@Name=’TaskName’]=’\DBPopulations\test1′]]
Sorry but it seems that when copying the code here, the quotes change to the wrong kind.
Worked for me – this is my event trigger:
*[EventData[@Name=’ActionStart’][Data[@Name=’TaskName’]=’\Development\Start NI Error Reporting Service’]]
Hello!
Thanks for a good article!
I have one question:
Is there a way to prevent running next task when previous was cancelled by user ?
I tried this way, but to no avail (
*[EventData[@Name=’StoppedOnRequest’][Data[@Name=’TaskName’]=’\taskname’]]
_tag-start_Suppress Path=”Microsoft-Windows-TaskScheduler/Operational”_tag_end_*[EventData[@Name=’StoppedOnRequest’][Data[@Name=’TaskName’]=’\Trol\PostgreSQL 1C bases backup\ACC_C_30_GK’]]_tag_start_/Suppress_tag_end_
_tag-start_Suppress Path=”Microsoft-Windows-TaskScheduler/Operational”_tag_end_*[EventData[@Name=’StoppedOnRequest’][Data[@Name=’TaskName’]=’\Trol\PostgreSQL 1C bases backup\ACC_C_30_GK’]]_tag_start_/Suppress_tag_end_
This is awesome! Thank you so much…works like a charm!!
How would I change the above code to look for multiple successes?
Code below is not working.
*[EventData
[@Name=’TaskSuccessEvent’]
[Data[@Name=’TaskName’]=’\SQL\LoanTran\LoanTran (191 – 195)’]]
and
*[EventData
[@Name=’TaskSuccessEvent’]
[Data[@Name=’TaskName’]=’\SQL\LoanTran\LoanTran (196 – 200)’]]
Tanks
It work for me nice and easy.