The Last Result
column of the Scheduled Tasks
Window on Windows Server 2003, displays the result of the execution of the .exe, .vbs, .ps1, .bat, .cmd, etc… that has been run at the scheduled time.
There is also an archived history of this value that appears in the Scheduled Tasks Log (Found on the Scheduled Tasks
Window under the Advanced->View Log
)
Now my question is, if I'm running a scheduled task that is a .exe, .vbs, .ps1, .bat, .cmd, etc… how do I use that process to return a specific Last Result
when the process ends?
P.S. If you think this question should be split up into smaller parts since I'm painting pretty broadly with it, just let me know and I'll split it into subsequent smaller questions
Best Answer
What you are talking about is called an exit code or error level.
The exit code would depend on the programming / scripting language used. For example to send a code 500:
PowerShell, .bat, .cmd =
exit 500
VBScript =
WScript.Quit 500
In C# you would declare the
Main
entry point with a return value of typeint
and then just callreturn 500;
. See https://stackoverflow.com/questions/155610/how-do-i-specify-the-exit-code-of-a-console-application-in-net for an example.