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

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

Tengo un problema con el Programador de tareas en Windows Server 2016 que no ejecuta tareas repetitivas después de deshabilitarlas y volverlas a habilitar.

Creo una tarea con un "Disparadores->Inicio" de cinco minutos en el futuro y configuro la tarea para que se ejecute cada cinco minutos. La opción "Configuración->Ejecutar tarea tan pronto como sea posible después de perderse el inicio programado" está marcada.

Todo funciona bien: la tarea se ejecuta a la hora de inicio programada y luego se ejecuta cada cinco minutos.

Deshabilite la tarea y espere más de cinco minutos.

Habilite la tarea, no se vuelve a ejecutar.

La hora de la próxima ejecución continúa actualizándose cada cinco minutos, pero la tarea no se ejecuta y la hora de la última ejecución nunca se actualiza.

No hay entradas en el Historial de tareas una vez que se vuelve a habilitar la tarea ni eventos en los registros de eventos de Windows.

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.

Respuesta1

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.

Respuesta2

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.

Respuesta3

This highlights the difference in behavior between a “Daily” task and a “One time” task. This is a bit counterintuitive, but if you want to be able to disable a task, then have it start firing automatically again right after you re-enable it, you need to make it a “One time” task rather than “Daily.”

Here is how they look in the task list (deliberately named to highlight the schedule differences):

Lista de tareas

When a Daily task is disabled and re-enabled, it will resume at its Start time (so, later that day or the next day):

Tareas diarias

If a One time task is disabled and re-enabled, it will resume as soon as one more repeat interval elapses, relative to its Start time.

tarea única

información relacionada