schtasks (create a task which runs every N hours infinitely)
I am using below schtasks command to schedule a task that runs every 5 hours. But it creates a task which ends after 3 days. I want to create a task which runs every 5hours infinitely:
schtasks /create /RU "SYSTEM" /sc hourly /mo 5 /tn "My App" /tr C:\Windows\System32\calc.exe
If I query the task it will below setting list(which says it end after 3days) using "SCHTASKS /Query"
HostName: WINX22
TaskName: \VHDLdapBackupTask_testdays
Next Run Time: 07-03-2012 07:00:00
Status: Ready
Logon Mode: Interactive only
Last Run Time: N/A
Last Result: 1
Author: Administrator
Task To Run: calc.exe
Start In: N/A
Comment: N/A
Scheduled Task State: Enabled
Idle Time: Disabled
Power Management: Stop On Battery Mode, No Start On Batteries
Run As User: WINX22\Administrator
Delete Task If Not Rescheduled: Enabled
Stop Task If Runs X Hours and X Mins: 72:00:00
Schedule: Scheduling data is not available in this format.
Schedule Type: One Time Only, Hourly
Start Time: 03:00:00
Start Date: 07-03-2012
End Date: N/A
Days: N/A
Months: N/A
Repeat: Every: 4 Hour(s), 0 Minute(s)
Repeat: Until: Time: None
Repeat: Until: Duration: Disabled
Repeat: Stop If Still Running: Disabled
March 7th, 2012 7:26am
The below command creates the task which runs infinitely. The property
Stop Task If Runs X Hours and X Mins: 72:00:00 indicates that system will end the task if it runs continuously for more than 72hours(3days).
schtasks /create /RU "SYSTEM" /sc hourly /mo 5 /tn "My App" /tr <application_path>
Free Windows Admin Tool Kit Click here and download it now
March 8th, 2012 4:31am
That statement is contradictory. Something won't run infinitely if it will be ended by the system after running continually for 3 days.
From what I can see the only way to use schtasks to create a task that does not have this setting applied is to use the /xml option - create your task as you are now, or manually, turn off the setting in Task Scheduler, then grab a copy of the xml file
from c:\windows\system32\tasks, then delete the task.
Then you can use schtasks /create /tn {name} /xml {xml-file}
Obviously if anything of the other properties need to be dynamic you'll have to create the xml programmatically, but at least now you have a template to use.
May 10th, 2012 5:27pm
"runs infinitely" is not the clearest terminology. What T_M means is that it will be started every 5 hours from now on. It will only be terminated if a single execution tries to run longer than 72 hours.
Free Windows Admin Tool Kit Click here and download it now
May 31st, 2012 5:08pm