17

I seem to be getting slightly confused by the Task Scheduler trigger settings. (I'm on Windows Server 2008 Web)

I want to create a task that will run every 5 minutes, whether a user is logged in or not, and that goes right back into it's schedule when the computer reboots.

And so, I have set it all up as required, but notice there are two options for my Trigger:

  1. Begin the task At Startup (and then use Advanced Settings to repeat every five minutes indefinitely)
  2. Begin the task At task creation/modification (and then use Advanced Settings to repeat every five minutes indefinitely)

If I choose (1), it won't run right away. I'll have to reboot, which I don't want to do.

If I choose (2), it will run right away, but won't after next reboot.

If I create triggers for both (1) and (2), it may work, but then when I ever modify the task in future, will there be two instances of it running as both triggers are fired? Or will it override the 5-minutely intervals that have began since startup? I don't want either to happen.

Any ideas?

2 Answers 2

27

I'd try it like this:

  1. Add a trigger: enter image description here Make sure to set the current date and 00:00:00 as the start time
  2. Make sure the task is run as soon as possible if the start was missed: enter image description here
1
  • 6
    Thanks. "Run as soon as possible if the start was missed" was the key.
    – Ross
    Mar 22, 2012 at 14:18
2

Here's how to create such scheduled task using PowerShell:

$executable = "foo.exe"
$taskName = "My Task"
$action = New-ScheduledTaskAction -execute $executable
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable
Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -Setting $settings -description $description -User "NT AUTHORITY\SYSTEM" -RunLevel 1
$trigger.RepetitionInterval = (New-TimeSpan -Minutes 5)
$trigger.RepetitionDuration = (New-TimeSpan -Days 1000)
Set-ScheduledTask $taskName -Trigger $trigger
1
  • Hullo I think this only works if Duration is infinite - ([timespan]::MaxValue)
    – Michael
    Jul 25, 2014 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.