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.


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


6 thoughts on “Why my scheduled task completes with return code 2

  1. 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…

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

  2. In my case, it was the batch file instructions.. even though the batch file ran perfectly when launched manually, a code 2 appeared when run by the task scheduler. At first I followed advice about permissions on the batch file and any source/destinations within, then ran as user logged in instead of not, the optional ‘start’ directory is not optional.. but I had it set right.. nothing worked.. UNTIL I had the batch file create its own log and discovered it did not like the references to mapped drives in its instructions. Even though the batch file runs fine manually.. I had to replace references to mapped locations with full UNC paths before they would execute properly when run by the task scheduler.

  3. I was running into the exact same issue. I resolved it by delaying the running of the batch to mount the drive by 1 minute after startup. The issue I was having is the error code of 2 which meant not able to find the path. So by delaying it, the drive was then available.

    1. I did all these— Run it with highest privileges, using UNC, delay the start. Still get the same problem. I can run my bat file manually outside the task scheduler successfully. Inside the task scheduler, I get message saying the task scheduler successfully finished the task with return code 2, and there is no report.

Leave a Reply to Thomas Thomassen Cancel reply
