Wednesday, July 18, 2012

Server 2008 scheduled task not working - action "C:\Windows\SYSTEM32\cmd.exe" with return code 1

MS server 2008 / R2 scheduled task the older server versions. Especially if you are trying to create the tasks using a command line batch script.

In server 2000 we used to run the following command and it would be enough:
schtasks /Create /S [machine name] /RU [domain user] /RP [password] /SC ONCE /TN [task name] /TR [batch name i.e. DoSomething.bat] /ST [StartTime] /SD [RunDate]

In the server 2008 world the above command will get scheduled and executed but will do nothing!
in the event log of the task scheduler, which is different than the usual application/system event logs, somewhere in there you will see a message in the lines of  [ action "C:\Windows\SYSTEM32\cmd.exe" with return code 1"]

Even looking at the task scheduler history would say that the task was executed and finished successfully!!!

The solution, add these 2 flag at the end of the command:

schtasks /Create /S [machine name] /RU [domain user] /RP [password] /SC ONCE /TN [task name] /TR [batch name i.e. DoSomething.bat] /ST [StartTime] /SD [RunDate] /RL HIGHEST  /F


If you are working on the server and scheduling the tasks using the GUI, here's a good link with screen shots of where these flags are hiding: WIN 2008 TASK SCHEDULER WITH RETURN CODE 1 (0X1)

No comments:

Post a Comment