M BUZZ CRAZE NEWS
// general

Creating a scheduled task in Windows that will run at intervals indefinitely

By Gabriel Cooper

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

I'd try it like this:

  1. Add a trigger:enter image description hereMake 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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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