Summary
When you run a program in the Scheduler, the Scheduler may report a status of "Completed with errors." The Scheduler may also log a message similar to the following:
Program <YOUR program>terminated with unacceptable return code 1
More Information
Whenever a program runs, it passes an exit code back to the operating system (or in this case the Scheduler) to indicate its exit status. Most programs return a value of 0 to indicate successful completion or some value greater than 0 to indicate a warning or error.
When you set up a program in the Scheduler, you can specify on the Advanced page a value for the "Highest acceptable return code." The value defaults to 0 if you do not change it. Whenever the program exits with a return code higher than the value you specify, the Scheduler reports the status as "Completed with errors." If you have checked the "Abnormal termination" box in the Logging section on the Advanced page, the Scheduler will log the unacceptable return code to the Event Log.
The Scheduler can only detect the exit code and inform you of the code; it does not know what the code means. This meaning will depend entirely on the application being run. Check the documentation for the application in question to see whether the return codes are documented.
If you cannot find documentation on the return codes, you should look for signs of unexpected or erroneous behavior on the part of the application.
If the application appears to be running properly, you can either ignore the return code or set the "Highest acceptable return code" to a higher value so the Scheduler will not treat it as an error.
Setting the Exit Code
If you are writing your own application the method you use to return an exit code will depend on your programming environment.
For a C, C++, or C# application the exit code is the return value from the main() function.
For a VB.NET application, the exit code is the return value from from the Main function.
To return an exit code from a VB6 application you may be able to use the Windows API ExitProcess function. This approach was previously detailed in Microsoft Knowledge Base article Q178357 (article no longer available), but is no longer supported or recommended by Microsoft due to the problems discussed in article Q288216. In addition to the problems described by Microsoft note that calling the ExitProcess function while your program is being debugged in the Visual Basic development environment will cause the Visual Basic IDE itself to terminate, along with your program.
For other development environments consult the appropriate documentation
A batch file returns the exit code of the last program executed by the batch file. If you want to set the exit code to a specific value, use this statement in your batch file:
exit /b exitcode
Where exitcode is the exit code you want to return. Note that this statement will terminate the batch file immediately.
See Also
Solving problems with scheduled programs
Diagnosing problems with batch files
All scheduled programs terminate immediately after being started, with a return code of 128