命令行大全

schtasks

舞夕之 发表于 2020-06-29 11:50浏览次数:

Schtasks命令使管理员可以在本地或远程系统上创建,删除,查询,更改,运行和结束计划任务。

查看英文版

目录:

1 schtasks 运行系统环境

2 schtasks 语法

3 schtasks 示例

schtasks 运行系统环境

Windows vista

Windows 7

Windows 8

Windows 10

schtasks 语法

SCHTASKS /parameter [arguments]
/Create 创建一个新的计划任务。
/Delete 删除计划的任务。
/Query 显示所有计划的任务。
/Change 更改计划任务的属性。
/Run 按需运行计划的任务。
/End 停止当前正在运行的计划任务。
/ShowSid 显示与计划的任务名称相对应的安全标识符。heduled 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 指定远程系统。如果省略,则系统参数默认为本地系统。
/U username 指定应该在其下执行SchTasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/RU username

指定运行任务的“运行方式”用户帐户(用户上下文)。

对于系统帐户,有效值为“”,“ NT AUTHORITY \ SYSTEM”或“ SYSTEM”。

对于v2任务,“ NT AUTHORITY \ LOCALSERVICE”和“ NT AUTHORITY \ 

NETWORKSERVICE”以及所有这三个的众所周知的SID也可用。

/RP [password]

指定“运行方式”用户的密码。要提示输入密码,该值必须为“ *”或无

。系统帐户将忽略此密码。必须与/ RU或/ XML开关结合使用。

/SC schedule

指定调度频率。有效的日程表类型:分钟,小时,每日,每周,每月

,一次,一次开始,一次登录,一次,一次,一次。

/MO modifier 改进计划类型,以更好地控制计划重复性。有效值在下面的修饰符部分列出。
/D days

指定运行任务的星期几。有效值:MON,TUE,WED,THU

,FRI,SAT,SUN和MONTHLY日程表1-31(每月的天)。通配符 “ *”指定全天。

/M months

指定一年中的月份。默认为每月的第一天。有效值:JAN,FEB,MAR,APR,

MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC。通配符“ *”指定所有月份。

/I idletimes 指定在运行计划的ONIDLE任务之前要等待的空闲时间。有效范围:1-999分钟。
/TN taskname 指定一个唯一标识此计划任务的名称。
/TR taskrun 指定在计划的时间运行的程序的路径和文件名。范例:C:\ windows \ system32 \ calc.exe
/ST starttime

指定运行任务的开始时间。时间格式为HH:mm(24小时制),例如14:30表示

2:30 PM如果未指定/ ST,则默认为当前时间。/ SC ONCE需要此选项。

/RI interval

指定重复间隔(以分钟为单位)。该间隔不适用于时间表类型

:MINUTE,HOURLY,ONSTART,ONLOGON,ONIDLE,ONEVENT。

有效范围:1-599940分钟。如果指定了/ ET或/ DU,则默认为10分钟。

/ET endtime

指定运行任务的结束时间。时间格式为HH:mm(24小时制),例如14:50表示

2:50 PM,不适用于时间表类型:ONSTART,ONLOGON,ONIDLE,ONEVENT。

/DU duration

指定运行任务的持续时间。时间格式为HH:mm,不适用于/ ET和时间表类型:

ONSTART,ONLOGON,ONIDLE和ONEVENT。对于/ V1任务,如果指定/ RI,则持续时间默认为1小时。

/K  

在结束时间或持续时间终止任务,不适用于计划类型:ONSTART,ONLOGON

,ONIDLE,ONEVENT。 必须指定/ ET或/ DU。

/SD startdate

指定任务运行的第一个日期。格式是mm / dd / yyyy。默认为当前日期

,不适用于时间表类型:ONCE,ONSTART,ONLOGON,ONIDLE,ONEVENT。

/ED enddate

指定任务应运行的最后日期。格式为mm / dd / yyyy,不适用于时间表类型

:ONCE,ONSTART,ONLOGON,ONIDLE和ONEVENT。

/EC ChannelName 指定OnEvent触发器的事件通道。
/IT   使任务仅在作业运行时当前已登录/ RU用户时才能交互式运行。仅当用户登录到计算机时,此任务才运行。
/NP   没有密码存储。任务以给定用户身份非交互地运行。仅本地资源可用。
/Z   将任务标记为要在最终运行后删除。
/XML xmlfile

根据文件中指定的任务XML创建任务。当任务XML已经包含主体时,可以与/ RU和/ RP开关

结合使用,或者与/ RP单独结合使用。

/V1   创建对Vista之前的平台可见的任务。与/ XML不兼容。
/F   如果指定的任务已经存在,则强制创建任务并禁止显示警告。
/RL level 设置作业的运行级别。有效值为LIMITED和HIGHEST。默认值为LIMITED。
/DELAY delaytime

指定触发触发器后延迟任务运行的等待时间。时间格式为mmmm:ss。此选项仅对日程表

类型ONSTART,ONLOGON,ONEVENT有效。

/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。
创建修改器

每个计划类型的/ MO开关的有效值:

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.

跳转到包括schtasks删除示例的示例。

SCHTASKS /Delete [/S system [/U username [/P [password]]]]         /TN taskname [/F] [/HRESULT] [/?]
/S system 指定远程连接的系统。
/U username 指定应该在其下执行schtasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/TN taskname 指定要删除的计划任务的名称。通配符“ *”可用于删除所有任务。
/F   如果指定的任务当前正在运行,则强制删除该任务并禁止显示警告。
/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。

跳转到包括schtasks删除示例的示例。

SCHTASKS /Query [/S system [/U username [/P [password]]]]         
[/FO format | /XML [xml_type]] [/NH] [/V]         [/TN taskname] [/HRESULT] [/?]
/S system 指定远程连接的系统。
/U username 指定应该在其下执行schtasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/FO format 指定输出的格式。有效值:TABLE,LIST,CSV。
/NH   指定列标题不应显示在输出中,并且仅对TABLE和CSV格式有效。
/V   显示详细任务输出。
/TN taskname 指定要检索其信息的任务名称,否则指定所有名称。
/XML [xml_type]

以XML格式显示任务定义。 如果xml_type为ONE,则输出将是一个有效的XML文件。

如果不存在xml_type,则输出将是所有XML任务定义的串联。

/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。

跳转至包括schtasks查询示例的示例。

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 指定远程连接的系统。
/U username 指定应该在其下执行schtasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/TN taskname 指定要更改的计划任务。
/RU username

更改必须在其下运行计划任务的用户名(用户上下文)。对于系统帐户,

有效值为“”,“ NT AUTHORITY \ SYSTEM”或“ SYSTEM”。对于v2任务,

“ NT AUTHORITY \ LOCALSERVICE”和“ NT AUTHORITY \ NETWORKSERVICE”

以及所有这三个的众所周知的SID也可用。

/RP password 指定现有用户上下文的新密码或新用户帐户的密码。系统帐户将忽略此密码。
/TR taskrun 指定计划的任务运行的新程序。
/ST starttime 指定运行任务的开始时间。时间格式为HH:mm(24小时制),例如14:30表示2:30 PM
/RI interval 指定重复间隔(以分钟为单位)。有效范围:1-599940分钟。
/ET endtime 指定运行任务的结束时间。时间格式为HH:mm(24小时制),例如14:50表示2:50 PM
/DU duration 指定运行任务的持续时间。时间格式为HH:mm,不适用于/ ET。
/K   在结束时间或持续时间终止任务。
/SD startdate 指定任务运行的第一个日期。格式是mm / dd / yyyy。
/ED enddate 指定任务应运行的最后日期。格式是mm / dd / yyyy。
/IT  

使任务仅在作业运行时当前已登录/ RU用户时才能交互式运行。仅当用户登录

到计算机时,此任务才运行。

/RL level 设置作业的运行级别。有效值为LIMITED和HIGHEST。默认为不更改。
/ENABLE   启用计划的任务。
/DISABLE   禁用计划的任务。
/Z   将任务标记为要在最终运行后删除。
/DELAY delaytime

指定触发触发器后延迟任务运行的等待时间。时间格式为mmmm:ss。此选

项仅对日程表类型ONSTART,ONLOGON,ONEVENT有效。 ONEVENT.

/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。

跳转到包括schtasks更改示例的示例。

SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I]         
/TN taskname [/HRESULT] [/?]
/S system 指定远程连接的系统。
/U username 指定应该在其下执行schtasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/I   通过忽略任何约束立即运行任务。
/TN taskname 标识现在要运行的计划任务。
/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。

跳转至包括schtasks运行示例的示例。

SCHTASKS /End [/S system [/U username [/P [password]]]]         
/TN taskname [/HRESULT] [/?]
/S system 指定远程连接的系统。
/U username 指定应该在其下执行schtasks.exe的用户上下文。
/P [password] 指定给定用户上下文的密码。如果省略,则提示输入。
/TN taskname 指定要终止的计划任务。
/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。

跳转至包括schtasks结束示例的示例。

SCHTASKS /ShowSid /TN taskname [/HRESULT] [/?]
/TN taskname 指定计划的任务名称。名称中不允许使用破折号。
/HRESULT   为了提高诊断能力,进程退出代码将为HRESULT格式。
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 as well as 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 wit

h /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 "*"

may be 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\NETWORKSER

VICE" are also available as well as 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:m

m (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:m

(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 示例

schtasks

单独运行时,schtasks显示所有任务名称,其下一个运行时间和状态。

Schtasks删除示例
SCHTASKS /Delete /TN "\Backup\Backup and Restore"

使用schtasks 删除“ 备份和还原”计划的任务。

Schtasks查询示例
SCHTASKS /Query /FO CSV /NH /V

使用schtasks 查询调度任务,并以CSV格式显示所有输出。

Schtasks更改示例
SCHTASKS /Change /TR restore.exe /TN "\Backup\Start Restore"

将restore.exe任务名更改为使用schtasks 开始还原。

Schtasks运行示例
SCHTASKS /Run /TN "\Backup\Start Backup"

使用schtasks 运行任务名称“ 开始备份”。

Schtasks结束示例
SCHTASKS /End /TN "\Backup\Start Backup"

结束任务名称使用schtasks 启动备份

Schtasks Showsid示例
SCHTASKS /ShowSid /TN "\Backup\Start Backup"

运行上面的命令将得到与以下示例类似的结果。

SUCCESS: The SID "S-1-5-17-2047162322-3971081939-4152322419-2583044571-537493394" for the username "Backup-Start Backup" has been computed successfully.
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 CSVformat.

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.

查看英文版

查看中文版