Using the Windows SCHTASKS command I'd like to create a Scheduled Task to run on Sunday at midnight (12:00 AM). However, I'd like this to run a maximum of 1 hour.

Running the following creates the scheduled task with all desired options except the maximum run time:

schtasks /create /tn "Scheduled - Weekly Defrag" /tr "'%windir%\system32\defrag.exe' -c -h -o -$" /D SUN /sc WEEKLY /ru System /f /ST 00:00

If I try to add the switches to specify the end time and termination (/ET 01:00 /K) the scheduled task defaults to a recurring interval of 10 minutes.

schtasks /create /tn "Scheduled - Weekly Defrag" /tr "'%windir%\system32\defrag.exe' -c -h -o -$" /D SUN /sc WEEKLY /ru System /f /ST 00:00 /ET 01:00 /K

The Windows GUI says the following now: "At 12:00 AM every Sunday of every week, starting 11/21/2016 - After triggered, repeat every 10 minutes indefinitely. Trigger expires at 11/21/2016 1:00:00 AM"

That "repeat every 10 minutes indefinitely" is assuredly not what I want, but it is the default interval. If I specify any interval, it still says that it will repeat at that specified interval. I don't want it to repeat at all. Is it even possible to not have a scheduled task repeat using SCHTASKS, or should I be using a different switch to force the task to terminate after a certain period of time with no recurring interval?

1 Answer 1


The only way I know (and I know it's a really bad solution), is to create a task the way you want it - then export it as XML (for example TaskExport.xml)

Then you create the task using the following :

schtasks /CREATE /TN "The task name" /xml "TaskExport.xml" /RU username /RP password
  • Thanks, it's worth a try at least since there appears to be no other alternative. I can package the XML and send it to the machine prior to creating the task, so that shouldn't be too problematic.
    – Beems
    Jan 5, 2017 at 21:11

You must log in to answer this question.

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