0

I've created an executable file from a c# program, in which the main method returns an integer value - 0 for success and 1 for failure.

I have a Windows Task Scheduler task which runs this executable file. However, no matter what the main method returns, the Task Scheduler will always display "Success" for this task, simply because the console window closed.

I have also tried creating a batch file to run the executable, and having the Task Scheduler run the batch file instead. The batch file looks like this:

start /d "c:\filepath" file.exe
if %ERRORLEVEL% NEQ 0 echo %ERRORLEVEL%

Currently this seems to have no effect on the Task Scheduler. How can I get the Task Scheduler to show that the task failed?

1 Answers1

0

You should specify an exit code other than the default value of 0 (which means success). You can do this using

Environment.Exit(someNumber)

For more details

Community
  • 1
  • 1
onatm
  • 816
  • 1
  • 11
  • 29
  • You mean from within the c# code, right? I tried that, and didn't see any difference. Task Scheduler still said Success. – Kristin Oct 29 '15 at 20:37
  • http://superuser.com/questions/330751/how-to-make-taskscheduler-fail-when-the-task-returns-result-different-from-0 – Squashman Oct 29 '15 at 21:35
  • Yeah, I did see that. My client specifically wants the Task Scheduler to show a failure, so I was hoping someone would have an idea of how to trick it into doing so. – Kristin Oct 29 '15 at 22:03