Scheduled tasks in Windows Server 2016 don't run after being disabled then enabled

1

1

I am having a problem with the Task Scheduler on Windows Server 2016 not running repetitive tasks after they are disabled and re-enabled.

I create a task with a “Triggers->Start” of five minutes in the future and set the task to run every five minutes. The “Settings->Run task as soon as possible after scheduled start is missed” option is checked.

Everything works fine – task runs at the scheduled Start time and then runs every five minutes.

Disable the task and wait more than five minutes.

Enable the task, it does not run again.

The Next Run time continues to update every five minutes but the task does not run and the Last Run Time is never updated.

There are no entries in the Task History once the task is re-enabled and no events in the Windows event logs.

When the start time is hit on the next day the task starts running again but this is not desirable as there can be a long delay between when the task is re-enabled and the start time comes again.

Tim Callahan

Posted 2018-01-05T21:26:20.110

Reputation: 41

Welcome to [su]! I believe the start trigger "At task creation/modificiation" will do the trick. I presume that manually enabling/disabling the task counts as a modification for these purposes. Otherwise, you could simply manually start the task whenever you re-enable it. – jpaugh – 2018-01-05T22:48:14.223

1@jpaugh Great idea, but I've tried this and that Trigger does not seem to fire when a task is enabled/disabled. – I say Reinstate Monica – 2018-01-05T22:51:19.767

Here are some alternatives which may be appropriate (in particular, the PowerShell option). I've never tried any of these, so YMMV.

– jpaugh – 2018-01-05T23:26:19.483

Answers

2

This is expected behavior. A task only starts when one of its Trigger conditions is met. The act of disabling the task has the same effect as stopping the task. Once that happens, it won't run again until a Trigger condition is met. Unfortunately the minimum interval when creating a new trigger is Daily, which is somewhat inflexible in your scenario.

Two options come to mind:

  • Instead of disabling the task to halt its execution, simply stop it. If you only need to stop execution for a short period of time, this may be all you need to do. However, if you need complete control over when the task starts or stops, don't define any Trigger conditions, then start/stop the task manually.
  • Create multiple Triggers such that a trigger will fire after the task is enabled. This is obviously not ideal, especially given your need to run the task every 5 minutes.

I say Reinstate Monica

Posted 2018-01-05T21:26:20.110

Reputation: 21 477

2

The task was set to run every day and repeat either indefinitely or daily. I changed it to Run Once and repeat indefinitely and it resumes execution when the task is enabled after having been disabled.

I think this works because When set up this way the scheduler displays "After triggered, repeat every 5 minutes indefinitely." So once the task is triggered it remains in the "triggered" state even when disabled so once enabled again it resumes running on the schedule.

NOTE: when first setting up the task the start time needs to be set in the future so that the task is triggered for the first time.

Tim Callahan

Posted 2018-01-05T21:26:20.110

Reputation: 41