8

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 ?

5

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

| improve this answer | |
  • 1
    This 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 2 '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. That's why it didn't work on your machine. – Esa Jokinen May 9 '17 at 16:04
5

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"
| improve this answer | |
1

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

| improve this answer | |
0

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.

| improve this answer | |
0

/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:56for this post !

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.