Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / Windows Server 2012 R2 / Schedule Task to Start When Another Task Finishes

April 13, 2016 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

 

14 comments
4
Facebook Twitter Google + Pinterest
previous post
SCCM and WMI Query to Find All Laptops and Desktops
next post
Disable Outlook Mailbox Auto-Mapping in Exchange

Related Reading

Updating the PowerShell Version on Windows

December 24, 2020

Zerologon (CVE-2020-1472): Critical Active Directory Vulnerability

December 4, 2020

How to Run CMD/Program under SYSTEM (LocalSystem) in...

December 3, 2020

Remote Desktop Services Is Currently Busy

October 27, 2020

How to Reduce Windows.edb Huge File Size?

October 19, 2020

14 comments

Dieter June 9, 2017 - 4:28 pm

Don’t work for me on Windows 10 x64

Reply
Terry Odom November 7, 2018 - 6:40 pm

For the section “Change the XPath code” it looks like you pasted the wrong code for us to use.

Reply
toto February 7, 2019 - 11:35 am

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’]]

Reply
admin February 8, 2019 - 5:12 pm

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.

Reply
Sigalit April 10, 2019 - 4:40 pm

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′]]

Reply
Sigalit April 10, 2019 - 4:43 pm

Sorry but it seems that when copying the code here, the quotes change to the wrong kind.

Reply
Chris February 11, 2019 - 7:31 pm

Worked for me – this is my event trigger:

*[EventData[@Name=’ActionStart’][Data[@Name=’TaskName’]=’\Development\Start NI Error Reporting Service’]]

Reply
RIS July 22, 2019 - 10:01 am

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 ?

Reply
RIS July 22, 2019 - 10:01 am

I tried this way, but to no avail (
*[EventData[@Name=’StoppedOnRequest’][Data[@Name=’TaskName’]=’\taskname’]]

Reply
RIS July 22, 2019 - 10:03 am

_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_

Reply
RIS July 22, 2019 - 10:02 am

_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_

Reply
Mark Davis January 2, 2020 - 12:03 am

This is awesome! Thank you so much…works like a charm!!

Reply
Bouwer February 11, 2020 - 1:46 pm

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)’]]

Reply
mahdi October 26, 2020 - 7:21 am

Tanks
It work for me nice and easy.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • How to Configure and Connect an iSCSI Disk on Windows Server?

    January 26, 2021
  • Preparing Windows for Adobe Flash End of Life on December 31, 2020

    January 22, 2021
  • Checking User Logon History in Active Directory Domain with PowerShell

    January 22, 2021
  • How to Disable/Remove Thumbs.db File on Network Folders in Windows?

    January 21, 2021
  • MS SQL Server 2019 Installation Guide: Basic Settings and Recommendations

    January 19, 2021
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

    January 15, 2021
  • Windows 10: No Internet Connection After Connecting to VPN Server

    January 13, 2021
  • Updating the PowerShell Version on Windows

    December 24, 2020
  • How to Enable and Configure User Disk Quotas in Windows?

    December 23, 2020
  • Restoring Deleted Active Directory Objects/Users

    December 21, 2020

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Granting Remote Access on SCManager to Non-admin Users
  • Fix: Server Stuck on “Preparing to Configure Windows”
  • The Remote Desktop Session Host Server Does Not Have a Remote Desktop License Server Specified
  • How to Run File Explorer Elevated
  • Printer Pooling: How to Configure a Printer Pool in Windows Server 2012 R2
  • How to Obtain SeDebugPrivilege when Debug Program Policy is Enabled
  • How to Install TFTP Server on Windows Server 2012 R2
Footer Logo

@2014 - 2018 - Windows OS Hub. All about operating systems for sysadmins


Back To Top