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.