Schtasks command

Updated: 11/12/2023 by Computer Hope
schtasks command

The schtasks command enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote system.

Availability

Schtasks is an external command that is available for the following Microsoft operating systems as schtasks.exe.

Schtasks syntax

SCHTASKS /parameter [arguments]
/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of the scheduled task.
/Run Runs the scheduled task on demand.
/End Stops the currently running scheduled task.
/ShowSid Shows the security identifier corresponding to a scheduled task name.
SCHTASKS /Create [/S system [/U username [/P [password]]]]         [/RU username [/RP password]] /SC schedule [/MO modifier] [/D day]         [/M months] [/I idletime] /TN taskname /TR taskrun [/ST starttime]         [/RI interval] [ {/ET endtime | /DU duration} [/K] [/XML xmlfile] [/V1]]         [/SD startdate] [/ED enddate] [/IT | /NP] [/Z] [/F] [/HRESULT] [/?]
/S system Specifies the remote system. If omitted, the system parameter defaults to the local system.
/U username Specifies the user context under which SchTasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/RU username Specifies the "run as" user account (user context) under which the task runs. For the system account, valid values are "", "NT AUTHORITY\SYSTEM" or "SYSTEM". For v2 tasks, "NT AUTHORITY\LOCALSERVICE" and "NT AUTHORITY\NETWORKSERVICE" are also available and the well-known SIDs for all three.
/RP [password] Specifies the password for the "run as" user. To prompt for the password, the value must be either "*" or none. This password is ignored for the system account. Must be combined with either /RU or /XML switch.
/SC schedule Specifies the schedule frequency. Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.
/MO modifier Refines the schedule type to allow finer control over schedule recurrence. Valid values are listed in the modifiers section below.
/D days Specifies the day of the week to run the task. Valid values: MON, TUE, WED, THU, FRI, SAT, SUN and for MONTHLY schedules 1 - 31 (days of the month). Wildcard "*" specifies all days.
/M months Specifies month(s) of the year. Defaults to the first day of the month. Valid values: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC. Wildcard "*" specifies all months.
/I idletimes Specifies the amount of idle time to wait before running a scheduled ONIDLE task. Valid range: 1 - 999 minutes.
/TN taskname Specifies a name which uniquely identifies this scheduled task.
/TR taskrun Specifies the path and file name of the program to be run at the scheduled time. Example: C:\windows\system32\calc.exe
/ST starttime Specifies the start time to run the task. The time format is HH:mm (24 hour time) for example, 14:30 for 2:30 P.M. Defaults to the current time if /ST is not specified. This option is required with /SC ONCE.
/RI interval Specifies the repetition interval in minutes. The interval is not applicable for schedule types: MINUTE, HOURLY, ONSTART, ONLOGON, ONIDLE, ONEVENT. Valid range: 1 - 599940 minutes. If either /ET or /DU is specified, then it defaults to 10 minutes.
/ET endtime Specifies the end time to run the task. The time format is HH:mm (24 hour time) for example, 14:50 for 2:50 P.M. and is not applicable for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT.
/DU duration Specifies the duration to run the task. The time format is HH:mm and is not applicable with /ET and for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT. For /V1 tasks, if /RI is specified, duration defaults to 1 hour.
/K   Terminates the task at the endtime or duration time and is not applicable for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT. Either /ET or /DU must be specified.
/SD startdate Specifies the first date on which the task runs. The format is mm/dd/yyyy. Defaults to the current date and is not applicable for schedule types: ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.
/ED enddate Specifies the last date when the task should run. The format is mm/dd/yyyy and is not applicable for schedule types: ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.
/EC ChannelName Specifies the event channel for OnEvent triggers.
/IT   Enables the task to run interactively only if the /RU user is currently logged on at the time the job runs. This task runs only if the user is logged in to the computer.
/NP   No password is stored. The task runs non-interactively as the given user. Only local resources are available.
/Z   Marks the task for deletion after its final run.
/XML xmlfile Creates a task from the task XML specified in a file. Can be combined with /RU and /RP switches, or with /RP alone, when task XML already contains the principal.
/V1   Creates a task visible to pre-Vista platforms. Not compatible with /XML.
/F   Forcefully creates the task and suppresses warnings if the specified task already exists.
/RL level Sets the runlevel for the job. Valid values are LIMITED and HIGHEST. The default is LIMITED.
/DELAY delaytime Specifies the wait time to delay the running of the task after the trigger is fired. The time format is mmmm:ss. This option is only valid for schedule types ONSTART, ONLOGON, ONEVENT.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Create modifiers

Valid values for the /MO switch per schedule type:

MINUTE:  1 - 1439 minutes.
HOURLY:  1 - 23 hours.
DAILY:   1 - 365 days.
WEEKLY:  weeks 1 - 52.
ONCE:    No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE:  No modifiers.
ONTHLY: 1 - 12, or FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.
ONEVENT:  XPath event query string.

Jump to examples including schtasks delete examples.

SCHTASKS /Delete [/S system [/U username [/P [password]]]]         /TN taskname [/F] [/HRESULT] [/?]
/S system Specifies the remote connected system.
/U username Specifies the user context under which schtasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/TN taskname Specifies the name of the scheduled task to delete. Wildcard "*" is used to delete all tasks.
/F   Forcefully deletes the task and suppresses warnings if the specified task is currently running.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Jump to examples including schtasks delete examples.

SCHTASKS /Query [/S system [/U username [/P [password]]]]         [/FO format | /XML [xml_type]] [/NH] [/V]         [/TN taskname] [/HRESULT] [/?]
/S system Specifies the remote connected system.
/U username Specifies the user context under which schtasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/FO format Specifies the format for the output. Valid values: TABLE, LIST, CSV.
/NH   Specifies that the column header should not display in the output and is valid only for TABLE and CSV format.
/V   Displays verbose task output.
/TN taskname Specifies the task name for which to retrieve the information, else all them.
/XML [xml_type] Displays task definitions in XML format.

If xml_type is ONE, the output will be one valid XML file.

If xml_type is not present, the output will be the concatenation of all XML task definitions.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Jump to examples including schtasks query examples.

SCHTASKS /Change [/S system [/U username [/P [password]]]] /TN taskname { [/RU runasuser] [/RP runaspassword] [/TR taskrun] [/ST starttime]         [/RI interval] [ {/ET endtime | /DU duration} [/K] ]         [/SD startdate] [/ED enddate] [/ENABLE | /DISABLE] [/IT] [/Z] } [/HRESULT] [/?]
/S system Specifies the remote connected system.
/U username Specifies the user context under which schtasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/TN taskname Specifies which scheduled task to change.
/RU username Changes the username (user context) under which the scheduled task has to run. For the system account, valid values are "", "NT AUTHORITY\SYSTEM" or "SYSTEM". For v2 tasks, "NT AUTHORITY\LOCALSERVICE" and "NT AUTHORITY\NETWORKSERVICE" are also available and the well-known SIDs for all three.
/RP password Specifies a new password for the existing user context or the password for a new user account. This password is ignored for the system account.
/TR taskrun Specifies the new program that the scheduled task runs.
/ST starttime Specifies the start time to run the task. The time format is HH:mm (24 hour time) for example, 14:30 for 2:30 P.M.
/RI interval Specifies the repetition interval in minutes. Valid range: 1 - 599940 minutes.
/ET endtime Specifies the end time to run the task. The time format is HH:mm (24 hour time) for example, 14:50 for 2:50 P.M.
/DU duration Specifies the duration to run the task. The time format is HH:mm and is not applicable with /ET.
/K   Terminates the task at the endtime or duration time.
/SD startdate Specifies the first date on which the task runs. The format is mm/dd/yyyy.
/ED enddate Specifies the last date when the task should run. The format is mm/dd/yyyy.
/IT   Enables the task to run interactively only if the /RU user is currently logged on at the time the job runs. This task runs only if the user is logged in to the computer.
/RL level Sets the runlevel for the job. Valid values are LIMITED and HIGHEST. The default is to not change it.
/ENABLE   Enables the scheduled task.
/DISABLE   Disables the scheduled task.
/Z   Marks the task for deletion after its final run.
/DELAY delaytime Specifies the wait time to delay the running of the task after the trigger is fired. The time format is mmmm:ss. This option is only valid for schedule types ONSTART, ONLOGON, ONEVENT.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Jump to examples including schtasks change examples.

SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I]         /TN taskname [/HRESULT] [/?]
/S system Specifies the remote connected system.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/I   Runs the task immediately by ignoring any constraint.
/TN taskname Identifies the scheduled task to run now.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Jump to examples including schtasks run examples.

SCHTASKS /End [/S system [/U username [/P [password]]]]         /TN taskname [/HRESULT] [/?]
/S system Specifies the remote connected system.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context. Prompts for input if omitted.
/TN taskname Specifies the scheduled task to terminate.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Jump to examples including schtasks end examples.

SCHTASKS /ShowSid /TN taskname [/HRESULT] [/?]
/TN taskname Specifies the scheduled task name. Dashes are not allowed in the name.
/HRESULT   For better diagnose ability, the process exit code will be in the HRESULT format.

Schtasks examples

schtasks

Run alone, schtasks displays all task names, their next run time, and the status.

Schtasks delete example

SCHTASKS /Delete /TN "\Backup\Backup and Restore"

Delete the Backup and Restore scheduled task using schtasks.

Schtasks query example

SCHTASKS /Query /FO CSV /NH /V

Query the schedule tasks using schtasks and display all output in CSV format.

Schtasks change example

SCHTASKS /Change /TR restore.exe /TN "\Backup\Start Restore"

Change the restore.exe taskname to Start Restore using schtasks.

Schtasks run example

SCHTASKS /Run /TN "\Backup\Start Backup"

Run the taskname Start Backup using schtasks.

Schtasks end example

SCHTASKS /End /TN "\Backup\Start Backup"

End the taskname Start Backup using schtasks.

Schtasks showsid example

SCHTASKS /ShowSid /TN "\Backup\Start Backup"

Running the above command would give results similar to the example below.

SUCCESS: The SID "S-1-5-17-2047162322-3971081939-4152322419-2583044571-537493394" for the username "Backup-Start Backup" has been computed successfully.