On a Windows 2008 Server I have a scheduled task which is configured to restart if the task fails. Everything works fine if the command succeeds.
However, if the command runs and returns a failure exit code (non-zero), the task does not restart.
Am I missing something? How do I get the task to restart if the command returns a failure code? Isn't this what the "restart on failure" setting supposed to do?
UPDATE
It appears this is by design. It looks like the "restart on failure" setting means to restart if the task scheduler for some reason cannot start the action command (e.g. login failure, ACL issue, etc). If the command is started successfully the task scheduler considers it successful, it doesn't care about the exit code.
I guess one way to work around this is to wrap the command in a script has the retry logic if it fails. Or use a different scheduler as someone suggested.
As far as I've ever been able to tell, this is designed behaviour. I've never been able to make it continue. I recommend springing for a better task scheduler (i.e. visualcron or similar) or setting your task up to run as a service.
Task scheduler 2.0 is better, but I think it STILL dies if the job never succeeds...So if you tell it to retry 100 times, and it can't make it work, it won't try again the next time.