How can I create a scheduled task from the command line that only runs on demand?

8,280

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.

Share:
8,280
Heretron
Author by

Heretron

Updated on September 18, 2022

Comments

  • Heretron
    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
    Heretron about 12 years
    This 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
    Heretron about 12 years
    When 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
    MikeAWood about 12 years
    When 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
    Molten Ice about 7 years
    Adding /sc once /sd 01/01/1901 /st 00:00 worked. It doesn't seem to work if one of those params are missing.
  • sactiw
    sactiw about 7 years
    /sc ONCE /st 00:00 would suffice the purpose