Speaking in Code

Friday, April 11, 2008

Scheduled Tasks: Exit Codes

After failing many attempts to get the Defrag.exe program to execute as a scheduled task, I found the Scheduler log file. It's a text file that comes up from the Scheduler 's Advanced | View Log menu. It said that my Defrag.exe jobs were completing with an "exit code of (2)" whatever that means.

Some Google searches later, I found a reference to a web site that lists all of Windows' command line exit codes.

http://www.hiteksoftware.com/mize/Knowledge/articles/049.htm

My exit code of (2) was identified as "file not found" and when I double-checked my command line on the Scheduler's task:
C:\WINDOWS\system32\defrag.exe c

I changed it to this, with a colon at the end:
C:\WINDOWS\system32\defrag.exe c:

That seemed to fix the problem. At least it ran for me manually. I'll have to wait and see if it runs automatically next Monday night.