Windows 2008 R2 Task Scheduler Failure

task-schedulerwindows-server-2008-r2

I have an application (.exe) which I am running via a scheduled task on Windows Server 2008 R2.
The task runs fine but when the .exe returns a non-zero exit code the task is still successful when it should fail.

I get this message:

Task Scheduler successfully completed
task "\CustomerDataSourceETL – Whics"
, instance
"{a574f6b4-2614-413c-8661-bc35eaeba7cd}"
, action
"E:\applications\CCDB-ETL\CustomerDataSourceETLConsole.exe" with return code 214794259.

How can I get task scheduler to detect that the return code is > 0 and fail the task?

Best Answer

I don't think there is anything you can do within Task Scheduler except manually check the 'Last Run Result' column. The event log also creates an informational entry in both cases.

The Task Scheduler in Vista and later comes with a better API than the older ones and you can use it to check for the LastTaskResult of your task.

I wrote a Windows Service that checks all my tasks every hour for any results not 0 and sends me an email if it found any. I could make it available if anybody is interested?

You could do the same with Powershell but then you would need Task Scheduler to schedule that script and you wouldn't get notified if the whole thing is down.