Task Scheduler - Batch script to run on condition that another task has completed

1

In Windows Server 2008 R2, I want to set up a Scheduled Task to run a batch script on the following condition

  -The task should only run once another task, that also runs a batch script, has   
   completed. How do I do that?

Note: Both task are set to run once daily.

Thanks!

DextrousDave

Posted 2013-07-03T10:18:34.087

Reputation: 385

Answers

1

Two ways that I see to do this:

  1. From within the first task, if it successfully completes, then immediately schedule the second task from the command line. Use schtasks.exe /create /? for syntax.

  2. If you want the second task to run nearly immediately, Call the second task, when you detect the first task has completed. If you want say, an hour to pass, use a 'wait.exe' type tool to temporarily pause the script, then execute after the time has passed.

RobW

Posted 2013-07-03T10:18:34.087

Reputation: 386

Cool thank you. I see that you can also use the schtasks command to call a specific task - How do I get the ID or the Process ID of a task? – DextrousDave – 2013-07-03T17:47:40.423

Mmm. Do you mean of the task created by the Scheduled Task? it is a batch program. Tasklist.exe - might get you to it. Also, check wmic.exe. – RobW – 2013-07-03T21:25:10.533

There is another program called getpids.exe http://www.scheibli.com/projects/getpids/ . It will return the current PID, parent pids (one of which is your cmd.exe). Youu would call it from your batch program and parse for Process ID.

– RobW – 2013-07-04T00:26:49.240