13

When creating a task with a batch file or command line, how do I specify the following option?

Run task as soon as possible after a scheduled start is missed

I know that this option exists via the GUI, but I need to specify it via command line.

3 Answers 3

13

There is no command line option for this. One workaround is to create the tasks with that option, using the GUI, then export it to an XML file. Then you can run it with

schtasks /create /TN "New Task" /xml "C:\TEMP\New Task.xml" /RU DOMAIN\username /RP password
2
  • Thank you so much. Exactly what I was looking for. Good to know its not possible with just commandline either. Sep 27, 2013 at 18:23
  • Anyone know if this is possible now after 4 years?
    – Robert
    Nov 28, 2017 at 3:19
7

Powershell to rescue, use -StartWhenAvailable

Set-ScheduledTask `
    -TaskName $TaskName `
    -TaskPath $TaskPath `
    -Trigger $(New-ScheduledTaskTrigger -At "01.01.2018 05:00:00" -DaysOfWeek $day -Weekly -Verbose) `
    -Settings $(New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries)
0
1

It can be done with VBscript too. In win 7 there is no Set-ScheduledTask in Powershell.

Set objTaskService = CreateObject("Schedule.Service")
objTaskService.Connect()

Set objRootFolder = objTaskService.GetFolder("\")
Set objTask = objTaskService.NewTask(0)

objTask.RegistrationInfo.Description = "My Scheduled Task"
objTask.Settings.Enabled = True
objTask.Settings.Hidden = False
objTask.Settings.StartWhenAvailable = True 'Run the task as soon as possible after a scheduled start is missed

Set objTrigger = objTask.Triggers.Create(1)
objTrigger.StartBoundary = "2023-04-08T12:00:00"
objTrigger.Enabled = True
objTrigger.Id = "DailyTrigger"
objTrigger.Repetition.Interval = "PT1M"
objTrigger.Repetition.Duration = "PT1H"

Set objAction = objTask.Actions.Create(0)
objAction.Path = "D:\Windows\System32\Notepad.exe"

objRootFolder.RegisterTaskDefinition "MyTask", objTask, 6, , , 3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .