Posted on April 13, 2016 · Posted in Windows Server 2012 R2

Schedule Task to Start When Another Task Finishes

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.

Task completed: eventid 102

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:

EventID: 102
Provider-Name: Microsoft-Windows-TaskScheduler
Channel: Microsoft-Windows-TaskScheduler/Operational
TaskName: \ping

event 102 xml view

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. Create task trigger: on an event

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:

new event filter

Create a new event filter by specifying the data from the XML View of the event:

Events Logs: Microsoft-Windows-TaskScheduler/Operational

Event source: TaskScheduler

Task category: Task completed

event filter by log

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>

event filter xpath

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>

event xml settings

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:

XPath explanation

 

Previous:
Next:
Related Articles