AndrewMo
AndrewMo

Reputation: 149

Creating dependencies in task scheduler

I have set up a couple of daily tasks that update a SQL table and then sends out an email with a CSV attached. 5 of the scheduled tasks only complete successfully if the first task runs successfully. How would I add an argument in Task Scheduler to run the sequential tasks only if the first task was completed successfully? The reasoning behind the request is due to the issue that sometimes the first script runs in a few minutes and other days it can take over an hour to complete. Any suggestions? Thank you

Upvotes: 4

Views: 11662

Answers (4)

David Hayes
David Hayes

Reputation: 7512

It can be done! See here http://blogs.msdn.com/b/davethompson/archive/2011/10/25/running-a-scheduled-task-after-another.aspx

In summary though say you have a task called Ping and you want a task called pong to run after it.

  1. Create a task called Pong
  2. Create an On an Event Trigger
  3. Select Custom and edit the XML to be something like this
     <QueryList>
        <Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
           <Select Path="Microsoft-Windows-TaskScheduler/Operational">*[EventData
     [@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\Ping']]</Select>
        </Query>
     </QueryList>

Upvotes: 4

C J
C J

Reputation: 173

We have run into this same need several times. The 2 ways we have created the 'Dependency' type functionality is to:

  1. Set the schedule to be run say every 30 minutes. In the startup of your app see if the dependency has been completed, if not exit, otherwise do you processing.

  2. When there have been multiple dependencies we created an app that managed those. Each process that needed to be run depending on the others would be launched from the new Controller App (CA)'. The CA is scheduled to run every 30 minutes (or what every makes sense for your process) and it controls the multiple apps by checking of the dependencies and running the next app. We don't leave the CA running, we spawn the process to run and exit. Next time CA launches it checks dependencies and takes action needed or exits till launched again.

Upvotes: 0

Booga Roo
Booga Roo

Reputation: 1781

If your task that takes a varying amount of time leaves a Windows Event Log entry Event ID code specific to the successful completion of that task, you should be able to make your other tasks use the task scheduler trigger type "On an event" with the associated Log, Source, and Event ID.

If it doesn't, the other proposals are probably the only options left.

Upvotes: 0

Paul
Paul

Reputation: 5871

I dont think what you want is possible with the windows task scheduler. I would propose that you start the scripts that depend on the first one running successfully from the first script itself. That way you can be sure it has finished its work.

Also the title of your question is kind of misleading, something like "Creating dependencies in TaskScheduler" would fit better.

Upvotes: 1

Related Questions