schtasks - create task with no schedule that runs on demand

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 ?


Solution 1:

Create the task and set it to start ONCE in the past. The task will exist and you can run it at will.

Solution 2:

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"

Solution 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