How can I create a scheduled task from the command line that only runs on demand?
You could always specify "/sd 01/01/1901" and have it specify the date as happening in the past. It should complain "WARNING: Task may not run because /ST is earlier than current time." for obvious reasons. But it should never actaully run without some intervention from you as it will never trigger the schedule to actaully execute.
You can't leave out the times (AFAIK) as the scheduler doesn't like that. As it is a bit counterintuitive for what the scheduler is for.
Heretron
Updated on September 18, 2022Comments
-
Heretron over 1 year
I"m trying to duplicate the steps in this article for creating a shortcut that launches a program without a UAC prompt. I'd like to create the task from the command line, however.
Here's the schtasks.exe command I'm using:
schtasks /create /tn MyTaskName /tr "c:\MyApplication.exe" /sc ONCE /st 00:00 /RL HIGHEST /RU BUILTIN\Administrators
The
/sc
and/st
switches are tripping me up. I don't want to specify a schedule or a start time but only run the task on demand. -
Heretron about 12 yearsThis may work. When I create the task from the UI, I can leave out the time but I can't seem to duplicate this from the command line.
-
Heretron about 12 yearsWhen I do this it still shows the UAC prompt. For our program, double-clicking the shortcut and then accepting UAC isn't the same as right-clicking and running as administrator.
-
MikeAWood about 12 yearsWhen creating the task in the UI, how are you leaving out the time? I don't see a way to do this without specifying either a dates or one fot eh following: "when the computer starts", "when i login", or "when a specific event is logged". Maybe you are doign something different. If you are using anothe roption you should be able to specify it on the command line.
-
Molten Ice about 7 yearsAdding
/sc once /sd 01/01/1901 /st 00:00
worked. It doesn't seem to work if one of those params are missing. -
sactiw about 7 years
/sc ONCE /st 00:00
would suffice the purpose