3

Windows schtasks.exe: What is the equivalent command line switch for ExecutionTimeLimit in schtasks. In the Edit Tasks dialog it is "Stop tasks if it runs longer than". I tried /ET end time and /DU duration but they imply a repetition. I only want a task to run once and then be killed x minutes later.

Paul M
  • 31
  • 3

2 Answers2

4

Not a perfect solution , but you can use /XML option of schtasks

schtasks /Create /tn jobname /XML Path_of_xml

Within the xml file you should able to use ExecutionTimeLimit to specify the time you want to kill the job .

You can get sample xml by export a exist job to get reference

schtasks /Query /tn jobname /XML > Path_of_xml

Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
yikaus
  • 188
  • 6
  • Nope, doesn't work if you change ExecutionTimeLimit in XML and then create task. It is automatically sets to 259200S. – DBenson Mar 27 '21 at 16:43
0

Using the Powershell it is possible to create a task where you can modify ExecutionTimeLimit to your value.

$MyPathToFile = 'C:\Path\File.exe'
$hour = '20:00:00'
$user = 'MyDomain\MyUserName'
$password = '123321Password'
$MyTask = 'MyTask'

$MyExecutionTimeLimit = '01:00:00' # HH:MM:SS

$trigger = New-ScheduledTaskTrigger -Daily -At $hour
$action = New-ScheduledTaskAction -Execute $MyPathToFile
$settingsSet = New-ScheduledTaskSettingsSet -ExecutionTimeLimit $MyExecutionTimeLimit
$task = New-ScheduledTask  -Action $action  -Trigger $trigger  -Settings $settingsSet 
Register-ScheduledTask -TaskName $MyTask -InputObject $task -User $user -Password $password
Peter
  • 1,589
  • 2
  • 20
  • 27