I am trying to use schtasks.exe
and create a one-time task that runs on demand. I just want to create the task without a schedule but the command schtasks /create /tn TestTask
fails with Invalid syntax. Mandatory option 'sc' is missing.
. Is there an option i am missing ?

- 235
- 1
- 3
- 7
5 Answers
Create the task and set it to start ONCE in the past. The task will exist and you can run it at will.

- 1,825
- 9
- 11
-
1This does not work on my machine - any other workaround you know of? We scheduled the task with ONCE on 1/1/2999, however, that's not a clean solution. – D.R. Jul 02 '15 at 13:42
-
2@D.R. We have a time traveler! For the rest of us, 1/1/2999 is not in the past. It's also after January 19, 2038 03:14:08 GMT, [The End of Unix Time](http://unixepoch.com/). That's why it didn't work on your machine. – Esa Jokinen May 09 '17 at 16:04
Instead of using a dummy time in the past or future, you can set the task to run on a dummy event:
SCHTASKS /Create /TN TaskOnEvent /TR notepad.exe /SC ONEVENT /EC Application /MO *[System/EventID=777] /f
Then you can run it on demand:
SCHTASKS /Run /TN "TaskOnEvent"
Or trigger it by logging the event:
EVENTCREATE /ID 777 /L APPLICATION /T INFORMATION /SO DummyEvent /D "Initiate scheduled task."
..Or create task in gui, export and call xml:
SCHTASKS /Create /TN "TaskOnEvent" /xml "C:\TaskOnEvent.xml"

- 71
- 1
- 3
/sc ONCE /st 00:00
should be sufficient to create a task that never triggers by its own and needs to be triggered explicitly

- 113
- 5
As mentioned already you can create task in gui, export and call xml:
SCHTASKS /Create /TN "TaskOnEvent" /xml "C:\TaskOnEvent.xml"
...You do NOT have to specify any triggers if you create via the GUI.

- 101
- 2
/sc once /st 00:00
will not work because you can't schedule a task in the past. But if you use the the CURRENT TIME, it will work, and the task will never be executed ... (but you'll get a warning though) .... tested under Windows 10 ...
/sc once /st 20:56
for this post !

- 101