Running SCHTASKS with ONSTART on WS08R2 remotely may not trigger

07 Oct

Ok found out about this today. Here is the story (both are ws08R2)

  • SVR1 – my script server in Singapore
  • SVR2 – the remote server I want to run the scheduled job in London.

I issued the following command at SVR1:

schtasks /CREATE /s SVR2 /ru me /rp pw /sc ONSTART _
/tn Job1 /tr "c:\runme.cmd"

Task got created on SVR2, I reboot the server but Job1 never kicked off after reboot! Why?

It turns out that if you issue a command from a remote server for ONSTART, the scheduled task property (Under Edit Trigger) called Activate will have a date time stamp of SVR1. This tells SVR2 that the job is only active after that time, which is 8 hours away (SGP is +8 hrs different from LDN)

There is no parameters in the schtasks that can modify this behaviour. (pull hair and curse at M$).

There are 2 workarounds that I can think of however:

A) Using XML

  • Precreate the tasks and export as an XML file.
  • Remove the tag “StartBoundary” under Trigger -> BootTrigger
  • Use this XML file to create the schedule task

This method will not work on w2k if you have more than one type of OS versions.

B) Run a schedule command to schedule the onstart task locally.

schtasks /create /s SVR2 /ru me /rp pw /once /sd 09/09/2011 _
/st 01:00 /tn Job2 /tr "schtasks /create /ru me /rp pm _
/sc onstart /tn Job1 /tr "c:\runme.cmd" /z

Then issue command

schtasks /run /s SVR2 /tn Job2

This will create a job2 that will create Job1 from the server SVR2 local. The /Z option will cause the task to be deleted after its been run, so that your password is not exposed!

Also you will notice that I used a really old date/time. This is on purpose. I use this method to create one time schedule job so that I can trigger them manually. If I create it with a future date, it may trigger without me wanting it to.

Also you notice I set 09/09/2011, sometimes I use 01/01 for month-day. The reason is that schtasks /SD command is dependent on the regional date/time settings. So if you have a generic script with /SD 11/24/2011, it may not work on a server with format DD/MM/YYYY. Having values 01/01 to 12/12 will ensure this will work regardless of MM/DD or DD/MM.

1 Comment

Posted by on October 7, 2011 in Windows


Tags: ,

One response to “Running SCHTASKS with ONSTART on WS08R2 remotely may not trigger

  1. Tim Collins

    September 26, 2014 at 4:11 am

    Just ran into this problem. You can use schtasks /change to change the activate time after you create the scheduled task.

    schtasks.exe /change /TN “TaskName” /sd 01/01/2001


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: