Programming Field

Schtasks /Run - DOS/Command Prompt Reference

Executes a registered scheduled task immediately. This is one of the commands (options) of Schtasks.

Syntax

schtasks[.exe] /Run [/S <remote-system> [/U <user-name> [/P [<password>]]]]
    /TN <task-name> [/I] [/HRESULT]

Options

/S <remote-system> Specifies the name of the computer (local/remote) where the task is registered. <remote-system> will be an IP address or hostname. If omitted, the local computer is the target.
/U <user-name> [/P [<password>]]

Specifies the login name and password when providing a computer name. You can specify a domain name in <user-name> (in the form of ‘domain\username’). If omitted, the user who executed this command will be used.

On ‘/P [<password>]’, if the entire ‘/P [<password>]’ is omitted, no password is set. If only ‘/P’ is specified (and ‘<password>’ is omitted), prompting the user to enter the password will occur (the entered password will be displayed as ‘*’ in the prompt).

/TN <task-name> Specifies the name of the task. If the task name contains space characters, you need to enclose it with ‘" "’. If the task exists within a folder hierarchy, include the path to the task as well.
/I

[Windows Vista or later] If conditions are set for task execution, executing the task with ‘/I’ ignores those conditions. For instance, a task registered with ‘schtasks /create’ might specify that it should only run when the system is connected to power, but with ‘/I’ specified, it will run even if not connected to power. (Without ‘/I’, it will be queued and wait until the conditions are met.)

However, if the task is already running, specifying ‘/I’ will not trigger its execution.

/HRESULT [Windows 10? or later] Changes the exit code of the Schtasks command to HRESULT. This is used when you want to perform detailed handling in case of errors.

Details

Using ‘/Run’ executes the command registered with the task, but unlike directly executing the command, if a user is specified for running the command when setting up the task, it will be executed under that user's context.

Depending on the task settings, specifying ‘/Run /I’ may not execute the task if it is already running. Tasks created with ‘schtasks /Create’ have an option set to ‘If task is already running, do not start a new instance’, so when executing tasks with ‘/Run’, especially in cases where the task execution takes time, it's important to be aware of whether the task is already running. (You can forcefully end it with ‘schtasks /End’.)

When you execute a task with ‘/Run’, it doesn't affect its schedule or recurring execution. If there's a scheduled time for the next execution, the task will still run at that time.

Samples

Sample

schtasks /run /tn HogePiyo /i

Runs the task ‘HogePiyo’ unconditionally.

See also