Why my scheduled task completes with return code 2

I recently had a task job scheduled in one of Windows server 2008 but kept getting a return code 2 every time it runs.

Task Scheduler successfully completed task "\RoomView" , instance "{fcc8337a-11b2-4e69-b101-a58bb8d18ead}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 2.

Obviously, even though it says Task Scheduler successfully completed task, the task didn’t complete what it supposed to do.

The return code 2, as part of the cmd command exit code, indicates that The system cannot find the file specified, meaning that the file in task cannot be found in specified location.

It doesn’t seem to be the case in the task I’ve scheduled. I had made sure all files are in the location where it belongs. And I can run the task manually outside the task scheduler. The only explanation why the scheduler threw this exit code is probably the security setting. Since I already set the task run under the admin account, I enforced it to run with the highest privileges, the option under General tab in task properties, just like Run as administrator.

image

And bingo, now I am finally getting 0 as the return code now, stating that program successfully completed.

image

  • Thomas Thomassen

    I had an issue when I need to use net use to mount a drive with the SYSTEM account so it would be availible to CrashPlan. Under Win7 (admin no UAC) it was no problem, under Vista (admin with UAC) I got return code 2. I had to uncheck the “Run with highest priveledges” checkbox before it would work.

    …go figure…

    • trevdev

      I also had this problem because I was piping the output to other files, in the scheduled task arguments. It didnt like that. So I put it all in a batch file and scheduled the batch file.