How does Windows Task Scheduler in Win7 recognize a failed task?

后端 未结 4 813
猫巷女王i
猫巷女王i 2020-12-14 16:31

I am working with Windows 7 and I have an application that returns zero (0x0) when successful and one (0x1) on error situations.

I have scheduled this app using Win

相关标签:
4条回答
  • 2020-12-14 17:00

    You can,

    1. activate history for Schedule (if not already)
    2. on a History "Action completed" right click "Attached Task to This Event..."
    3. Set a custom filter like this:

      *[System[(EventID=201)]] and *[EventData[Data[@Name='ResultCode']='1']]

    Enjoy

    Tilo

    used on Win 2008 R2 (Exchange as email server)

    0 讨论(0)
  • 2020-12-14 17:01

    Create a new task and set the custom event query like this:

    <QueryList>
      <Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
        <Select Path="Microsoft-Windows-TaskScheduler/Operational">*[System[EventID=201]] and *[EventData[Data[@Name='ResultCode']!='0']] and *[EventData[Data[@Name='TaskName']='\YOUR TASK NAME HERE']]</Select>
      </Query>
    </QueryList>
    

    Set the trigger advanced settings to Delay the task for a period of time like 15 minutes.

    Configure the action of the new task to start a program:

    Program/script:

    schtasks
    

    Add arguments:

    /Run /TN "\YOUR TASK NAME HERE"
    

    This will schedule the original task to run again 15 minutes after a non-zero result code is logged in the event.

    0 讨论(0)
  • 2020-12-14 17:02

    I've experienced the same problem on a Windows 2008 server Windows Task Scheduler. The action return a non zero code but the scheduler consider the task completed:

    Task Scheduler successfully completed task "\SET Tasks\Scheduled task [Backup SET Server]" , instance "{...}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 1.
    

    I've found on the web only one answer:

    The Windows Task Scheduler does not examine the exit code or any other values when your task completes. You must handle any error processing within your own script or program.

    ...in this document: www.onlinetoolworks.com/docs/winTaskSched.doc

    So I think now that the only way to workaround this problem may be to use task triggering on event. I'm investigating.

    Regards,

    Olivier.

    0 讨论(0)
  • 2020-12-14 17:12

    Nobody has answered the title question though. It seems as though the task scheduler has no way to detect a failed task? Surely it must have something because it has an option to restart failed tasks!

    0 讨论(0)
提交回复
热议问题