Programming Field

Schtasks - DOS/Command Prompt Reference

[Windows XP (Pro?) or later] Manages such as task registration and deletion in ‘Task Scheduler’.

Syntax

schtasks[.exe] [/<operation>] [<parameters>...]

Options

/<operation>

Specifies operations related to tasks. You need to specify with ‘/’. (case insensitive.)

/Create Creates a task.
/Delete Deletes (unregisters) a task.
/Query Lists registered tasks.
/Change Modifies properties (settings) of the registered task.
/Run Executes the task.
/End Terminates the task.
/ShowSid [Windows Vista or later] Calculates the security identifier (SID) corresponding to the task.

If this option is omitted, it is treated as /Query specified.

<parameters>... Specifies parameters (options) to use with the above option. Except for /Query, there are mandatory parameters that must be specified.

Details

About Schtasks

‘Schtasks’ is a program that performs tasks such as task registration and deletion based on the specified options (operations). It can be considered as the command-line version of ‘Task Scheduler’ (taskschd.msc) in Windows GUI. It serves a role similar to cron in Linux systems.

Schtasks has the following operations. For more details of operations and options, please see the following pages.

The task names

For all operations, the task name can be specified as ‘/TN <task-name>’ (it can only be omitted in /Query). Use /TN to specify the task to operate on.

The task name can generally use the same characters as the file name, but if the ‘\’ character is included, the characters before it are treated as ‘folders’. For example, using the name ‘Hoge\Piyo\FooTask’ would be treated as ‘FooTask inside Piyo folder inside Hoge folder’. Folders are mainly used for grouping tasks.

* Even if you delete all tasks within a folder, the folder itself remains. Since the Schtasks command cannot delete folders themselves, you need to use ‘Task Scheduler’ in such cases. (You can also manually delete folders created under C:\Windows\System32\Tasks, but it seems that a system restart is required for the changes to take effect.)

Exit codes

Schtasks returns exit code 0 upon successful command execution and 1 upon failure.

[Windows 10 or later] In operations with the ‘/HRESULT’ option, specifying the ‘/HRESULT’ option will result in a negative exit code when the command fails. This negative value will represent a detailed value (HRESULT value) indicating the reason for the failure, making it useful for special handling in case of failure.

* If an operation is canceled by user input, whether it is considered successful (exit code 0) or failed (exit code 1) will depend on the command. However, if interrupted by Ctrl+C, it will result in a negative value (-1073741510).

See also