2

I have two tasks set up in the Windows Task Scheduler. One is supposed to run at 3:00 AM, and the other is supposed to run 15 minutes later. If the computer is off when the tasks are scheduled to run, then the tasks are set to be run when the computer starts up. The problem with this is that the two tasks cannot run at the same time. What I want to do is wait for the first of two tasks to complete, and once it has completed, wait 15 minutes before the second task begins. How can I set this up in the Task Scheduler? I can't set the system up for the second task to begin executing as soon as the first one is done because the two tasks are nothing more than batch files which invoke another program, and the two things that those batch files do with the program cannot be done at the same time. Since the first task should only take 5 minutes, I need to give some leeway for the second task to begin.

6
  • Could the first batch file not just call the second batch file just before exiting?
    – panhandel
    Jan 16, 2014 at 22:34
  • @panhandel I thought of that already. The problem is that the batch file starts the program and closes so that the console doesn't remain open. The way it is set up, the second batch file would be called immediately once the program is opened. Jan 16, 2014 at 22:36
  • 1
    Hmm. Hip shot here, but batch "START /WAIT {cmd}" perhaps? serverfault.com/questions/245393/…
    – panhandel
    Jan 16, 2014 at 22:39
  • @panhandel I am trying to find an ideal way to do this using a task trigger. I am looking through the options (On a schedule, On an event, etc), but I don't know how to configure any of these to do what it is I am trying to do. Jan 16, 2014 at 22:44
  • Hopefully that 'At' works for you. I found an interesting lead based on querying the event log via XML, but once the first task has completed once, it will never fire the second task again - more here: goo.gl/LtozZ4
    – panhandel
    Jan 17, 2014 at 0:14

2 Answers 2

2

You could use Schtasks or At from the batch file and schedule the task 15 minutes into the future.

3
  • I think that Schtasks is capable of doing what I am looking for, but the page has too much information on it. I looked at At (no pun intended), and it did not seem as useful. Jan 16, 2014 at 23:33
  • ss64.com/nt/schtasks.html that should provide some more "hands-on" examples. At is a mostly deprecated version, left over mostly for backwards compatibility.
    – JSanchez
    Jan 16, 2014 at 23:39
  • Okay, thanks! This is the method that I am going to use! Jan 16, 2014 at 23:42
1

I appreciate this has already been marked as answered but I have a requirement in my scenario where I'm not able to modify the 'triggering' task.

The solution is to create a task with a custom event filter trigger which fires when the trigger task completes. The source for this solution comes from here but I've explained the main part below.

In Task Scheduler select the trigger task and in the pane below select the History tab. Assuming this task has completed at least once before you should be able to see an event with a Task Category of Task Completed. Right click on the Task Completed event and select Event Properties. In the Details tab of the Event Properties window which opens select the XML View which should look something like this (potentially sensitive information removed):

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" /> 
        <EventID>102</EventID> 
        <Version>0</Version> 
        <Level>4</Level> 
        <Task>102</Task> 
        <Opcode>2</Opcode> 
        <Keywords>0x8000000000000001</Keywords> 
        <TimeCreated SystemTime="2014-01-21T15:28:27.746689500Z" /> 
        <EventRecordID>978</EventRecordID> 
        <Correlation ActivityID="{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" /> 
        <Execution ProcessID="10656" ThreadID="11656" /> 
        <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel> 
        <Computer>XXXXXXXXXXXXXXXXXXXXXXXXXX</Computer> 
        <Security UserID="S-X-X-XX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXX" /> 
    </System>
    <EventData Name="TaskSuccessEvent">
        <Data Name="TaskName">\ping</Data> 
        <Data Name="UserContext">XXXXXXXXXX\XXXXXXXXXXXXX</Data> 
        <Data Name="InstanceId">{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}</Data> 
    </EventData>
</Event>

The custom trigger you need to write is basically an XPath expression which evaluates to a filter which matches the Task Completed event of the triggering task. With a task named "ping" the trigger would be:

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

In the Edit Trigger window you can then set 'Delay task for: 15 minutes' which should achieve the desired result without needing to modify the original task.

There are loads of other XPaths that one could write to make fancier triggers. This blog post provides a bit more information and this Microsoft documentation seems like a good start for deeper reading.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .