SCHTASKS命令参数 :允许管理员在本地或远程系统上创建、删除、查询、更改、运行和结束定时任务
C:\Windows\System32\Tasks文件夹下的XML文件是用来存储Windows操作系统中计划任务的信息的。
Windows操作系统通过这些XML文件来管理和存储各种预定的任务,例如定时备份、系统维护、自动更新等。
这些任务可以在特定的时间或事件发生时自动执行,而XML文件则包含了这些任务的配置信息。
这些XML文件通常由Windows Task Scheduler服务使用,它负责在特定的时间点或特定的条件下执行这些任务。通过任务计划程序界面或使用命令行工具(如schtasks)可以创建、修改和删除这些任务,而相关的配置信息就会被保存在这些XML文件中。
要使用这些XML文件,你可以通过任务计划程序界面进行管理,也可以使用命令行工具(如schtasks)来操作这些任务。通过编辑这些XML文件,你也可以手动调整任务的配置参数。
%systemroot%\system32\tasks
C:\Windows\System32\Tasks
文件夹下面 全是XML 配置文件
%systemroot%
是一个环境变量,通常指向Windows操作系统的安装目录。在大多数情况下,它指向 C:\Windows
目录。使用 %systemroot%
环境变量可以使系统更加灵活和可移植,因为无论Windows操作系统安装在哪个驱动器上,都可以通过这个环境变量来引用Windows目录。
关于基础技术原理,%systemroot%
环境变量涉及到以下方面的基础技术:
-
环境变量:环境变量是操作系统中用来存储特定信息的动态值。它们对于配置和控制应用程序行为非常重要。
-
系统路径:
%systemroot%
在系统中被广泛使用,特别是在批处理脚本和命令行操作中。了解系统路径的设置和使用可以帮助管理和维护Windows系统。 -
操作系统结构:
%systemroot%
的存在反映了操作系统的结构设计,即将系统文件和核心组件存放在一个独立的目录中,便于管理和维护。 -
系统部署和管理:在系统部署和管理过程中,了解和利用
%systemroot%
变量可以帮助管理员更好地管理系统资源,并编写更具可移植性的脚本和配置。
总的来说,%systemroot%
环境变量涉及到操作系统的结构、环境变量的使用和系统管理等基础技术原理。
除了 %systemroot%
,在Windows操作系统中还有一些其他常用的环境变量,它们在系统管理和应用程序开发中发挥着重要作用。以下是一些常见的Windows环境变量及其作用:
-
%USERPROFILE%:指向当前用户的个人文件夹,通常为
C:\Users\用户名
。这个变量可以帮助访问用户的个人文件和设置。 -
%PATH%:包含一组目录路径,系统会在这些路径中查找可执行文件。通过将程序的可执行文件路径添加到
%PATH%
中,可以在命令行中直接执行该程序。 -
%TEMP% 和 %TMP%:分别指向用于存储临时文件的目录。程序可以使用这些变量来保存临时数据,并确保在不同系统上具有一致的行为。
-
%PROGRAMFILES% 和 %PROGRAMFILES(x86)%:分别指向安装的应用程序的默认目录。
%PROGRAMFILES%
在64位系统上指向C:\Program Files
,而%PROGRAMFILES(x86)%
则指向C:\Program Files (x86)
。 -
%SystemDrive%:指向系统安装所在的驱动器。通常为
C:
,但在某些情况下可能会安装在其他驱动器上。 -
%COMPUTERNAME%:指向计算机的名称,用于标识网络中的计算机。
-
%USERNAME%:指向当前登录用户的用户名。
这些环境变量在Windows系统中被广泛使用,可以简化系统管理、脚本编写和应用程序开发过程中的路径和配置管理。
除了之前提到的环境变量之外,Windows操作系统还有一些其他常用的环境变量,它们在系统管理和应用程序开发中也都有各自的作用。以下是另外一些常见的Windows环境变量及其作用:
-
%APPDATA%:指向当前用户的应用程序数据目录,通常为
C:\Users\用户名\AppData\Roaming
。这个变量用于存储应用程序的设置和数据。 -
%HOMEPATH%:指向当前用户的用户文件夹路径(不包括驱动器信息),通常为
\Users\用户名
。 -
%LOGONSERVER%:指向处理当前登录请求的域控制器的名称。
-
%OS%:指向当前操作系统的名称。
-
%NUMBER_OF_PROCESSORS% 和 %PROCESSOR_ARCHITECTURE%:分别指向系统中安装的处理器数量和处理器架构。
-
%SystemRoot%:与
%systemroot%
类似,都指向Windows系统的安装目录。 -
%TEMP% 和 %TMP%:这两个变量也被广泛使用,它们分别指向用于存储临时文件的目录。
这些环境变量在Windows系统中起着重要的作用,能够简化系统配置、管理和应用程序开发过程中的路径和设置管理。通过合理利用这些环境变量,可以使系统更加灵活、可移植和易于管理。
Windows操作系统还有一些其他常用的环境变量。以下是另外一些常见的Windows环境变量及其作用:
-
%ALLUSERSPROFILE%:指向所有用户共享的配置文件和数据的目录,通常为
C:\ProgramData
。 -
%PUBLIC%:指向公共文件夹的路径,通常为
C:\Users\Public
。 -
%COMSPEC%:指向命令解释器的可执行文件路径,默认为
C:\Windows\System32\cmd.exe
。 -
%SystemDrive% 和 %SystemRoot%:
%SystemDrive%
指向系统安装所在的驱动器,通常为C:
;%SystemRoot%
则指向Windows系统目录,通常为%SystemDrive%\Windows
。 -
%ProgramData%:指向程序数据的默认存储位置,通常为
C:\ProgramData
。 -
%CommonProgramFiles% 和 %CommonProgramFiles(x86)%:分别指向用于存储共享程序文件的目录,通常为
C:\Program Files\Common Files
和C:\Program Files (x86)\Common Files
。 -
%USERDOMAIN%:指向当前用户所属的域名。
以下是另外一些常见的Windows环境变量及其作用:
-
%USERDOMAIN_ROAMINGPROFILE%:指向用户域的漫游配置文件路径。
-
%APPDATA%:指向当前用户的应用程序数据目录,通常为
C:\Users\用户名\AppData\Roaming
。这个变量用于存储应用程序的设置和数据。 -
%LOCALAPPDATA%:指向当前用户的本地应用程序数据目录,通常为
C:\Users\用户名\AppData\Local
。这个变量用于存储应用程序的本地设置和数据。 -
%PUBLIC%:指向公共文件夹的路径,通常为
C:\Users\Public
。该变量用于访问公共文件夹中的内容。 -
%USERPROFILE%:指向当前用户的个人文件夹,通常为
C:\Users\用户名
。可以使用这个变量来访问用户的个人文件和设置。 -
%SystemDrive% 和 %SystemRoot%:
%SystemDrive%
指向系统安装所在的驱动器,通常为C:
;%SystemRoot%
则指向Windows系统目录,通常为%SystemDrive%\Windows
。 -
%SESSIONNAME%:指示当前会话的名称。
SCHTASKS /parameter [arguments] 描述: 参数列表: /Delete 删除定时任务。 /Query 显示所有定时任务。 /Change 更改定时任务的属性。 /Run 按需运行定时任务。 /End 停止当前正在运行的定时任务。 /ShowSid 显示与定时任务名称对应的安全标识符。 /? 显示此帮助消息。 |
schtasks /create /? SCHTASKS /Create [/S system [/U username [/P [password]]]] Description: Parameter List: /U username Specifies the user context under which SchTasks.exe /P [password] Specifies the password for the given user context. /RU username Specifies the "run as" user account (user context) /RP [password] Specifies the password for the "run as" user. /SC schedule Specifies the schedule frequency. /MO modifier Refines the schedule type to allow finer control over /D days Specifies the day of the week to run the task. Valid /M months Specifies month(s) of the year. Defaults to the first /I idletime Specifies the amount of idle time to wait before /TN taskname Specifies the string in the form of path\name /TR taskrun Specifies the path and file name of the program to be /ST starttime Specifies the start time to run the task. The time /RI interval Specifies the repetition interval in minutes. This is /ET endtime Specifies the end time to run the task. The time format /DU duration Specifies the duration to run the task. The time /K Terminates the task at the endtime or duration time. /SD startdate Specifies the first date on which the task runs. The /ED enddate Specifies the last date when the task should run. The /EC ChannelName Specifies the event channel for OnEvent triggers. /IT Enables the task to run interactively only if the /RU /NP No password is stored. The task runs non-interactively /Z Marks the task for deletion after its final run. /XML xmlfile Creates a task from the task XML specified in a file. /V1 Creates a task visible to pre-Vista platforms. /F Forcefully creates the task and suppresses warnings if /RL level Sets the Run Level for the job. Valid values are /DELAY delaytime Specifies the wait time to delay the running of the /HRESULT For better diagnosability, the process exit code /? Displays this help message. Modifiers: Valid values for the /MO switch per schedule type: ONEVENT: XPath event query string. SCHTASKS /Create /S ABC /U user /P password /RU runasuser ==> Creates a scheduled task "accountant" on the remote machine SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE ==> Creates a scheduled task "gametime" to run freecell on the SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime ==> Creates a scheduled task "report" on remote machine "ABC" SCHTASKS /Create /S ABC /U user /P password /RU runasuser ==> Creates a scheduled task "logtracker" on remote machine "ABC" SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE ==> Creates a scheduled task "gaming" to run freecell.exe starting SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00 SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT |
schtasks /create /? SCHTASKS /Create [/S system [/U username [/P [password]]]] 描述: 参数列表: /U username 指定 SchTasks.exe 应以哪个用户上下文执行。 /P [password] 指定给定用户上下文的密码。如果省略,则会提示输入密码。 /RU username 指定任务运行的“作为”用户帐户(用户上下文)。对于系统帐户,有效值为""、"NT AUTHORITY\SYSTEM"或"SYSTEM"。 /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 idletime 指定等待运行预定的ONIDLE任务之前的空闲时间量。 /TN taskname 指定以路径\名称形式的字符串,唯一标识此定时任务。 /TR taskrun 指定要在预定时间运行的程序的路径和文件名。 /ST starttime 指定运行任务的开始时间。时间格式为HH:mm(24小时制),例如,14:30表示下午2:30。如果未指定/ST,则默认为当前时间。对于/SC ONCE,此选项是必需的。 /RI interval 指定重复间隔(以分钟为单位)。不适用于计划类型:MINUTE、HOURLY、ONSTART、ONLOGON、ONIDLE、ONEVENT。 /ET endtime 指定任务结束时间。时间格式为HH:mm(24小时制),例如,14:50表示下午2:50。不适用于计划类型:ONSTART、ONLOGON、ONIDLE、ONEVENT。 /DU duration 指定任务运行的持续时间。时间格式为HH:mm。不适用于/ET和计划类型:ONSTART、ONLOGON、ONIDLE、ONEVENT。 /K 在结束时间或持续时间到达时终止任务。不适用于计划类型:ONSTART、ONLOGON、ONIDLE、ONEVENT。必须指定/Et或/DU。 /SD startdate 指定任务运行的第一个日期。格式为yyyy/mm/dd。默认为当前日期。不适用于计划类型:ONCE、ONSTART、ONLOGON、ONIDLE、ONEVENT。 /ED enddate 指定任务应该运行的最后日期。格式为yyyy/mm/dd。不适用于计划类型:ONCE、ONSTART、ONLOGON、ONIDLE、ONEVENT。 /EC ChannelName 指定OnEvent触发器的事件通道。 /IT 仅当/RU用户在作业运行时当前已登录时,才启用任务以交互方式运行。仅当用户已登录时,此任务才会运行。 /NP 不存储密码。以给定用户身份非交互方式运行任务。只有本地资源可用。 /Z 标记任务在最后一次运行后删除。 /XML xmlfile 使用文件中指定的任务XML创建任务。可以与/RU和/RP开关结合使用,或仅与/RP结合使用,当任务XML已包含主体时。 /V1 创建一个对较早版本可见的任务。 /F 强制创建任务,并抑制如果指定任务已存在时的警告。 /RL level 设置作业的运行级别。有效值为LIMITED和HIGHEST。默认值为LIMITED。 /DELAY delaytime 指定触发器触发后运行任务的等待时间。时间格式为mmmm:ss。此选项仅适用于计划类型ONSTART、ONLOGON、ONEVENT。 /HRESULT 为了更好地诊断,进程退出代码将采用HRESULT格式。 /? 显示此帮助消息。 ONEVENT: XPath事件查询字符串。 SCHTASKS /Create /S ABC /U user /P password /RU runasuser ==> 在远程计算机“ABC”上创建一个名为“accountant”的定时任务,从指定的开始时间到结束时间每五分钟运行一次calc.exe,在指定的开始日期和结束日期之间运行。 SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE ==> 创建一个名为“gametime”的定时任务,在每个月的第一个星期日运行freecell。 SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime ==> 在远程计算机“ABC”上创建一个名为“report”的定时任务,每周运行notepad.exe。 SCHTASKS /Create /S ABC /U user /P password /RU runasuser ==> 在远程计算机“ABC”上创建一个名为“logtracker”的定时任务,每五分钟从指定的开始时间开始运行notepad.exe,没有结束时间。将提示输入/RP密码。 SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE ==> 创建一个名为“gaming”的定时任务,每天从12:00开始运行freecell.exe,并在14:00自动终止。 SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00 ==> 创建一个名为“EventLog”的定时任务,当System通道中发布事件101时开始运行wevtvwr.msc。 SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT ==> 文件路径中的空格可以通过使用两组引号来实现,一组用于CMD.EXE,一组用于SchTasks.exe。CMD的外部引号需要是双引号;内部引号可以是单引号或转义双引号: |
SCHTASKS /Run /? SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I] Description: Parameter List: /U username Specifies the user context under /P [password] Specifies the password for the given /I Runs the task immediately by ignoring any constraint. /TN taskname Specifies the path\name of the task to run now. /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /Run /? 描述: 参数列表: /U username 指定 schtasks.exe 应在哪个用户上下文中执行。 /P [password] 指定给定用户上下文的密码。如果省略,则会提示输入。 /I 通过忽略任何约束条件立即运行任务。 /TN taskname 指定要立即运行的任务的路径\名称。 /HRESULT 为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。 /? 显示此帮助消息。 |
SCHTASKS /End /? SCHTASKS /End [/S system [/U username [/P [password]]]] Description: Parameter List: /U username Specifies the user context under /P [password] Specifies the password for the given /TN taskname Specifies the path\name of the task to terminate. /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /End /? 描述: 参数列表: /U username 指定 schtasks.exe 应在哪个用户上下文中执行。 /P [password] 指定给定用户上下文的密码。如果省略,则会提示输入。 /TN taskname 指定要终止的任务的路径\名称。 /HRESULT 为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。 /? 显示此帮助消息。 |
SCHTASKS /Query /? SCHTASKS /Query [/S system [/U username [/P [password]]]] Description: Parameter List: /U username Specifies the user context under /P [password] Specifies the password for the given /FO format Specifies the format for the output. /NH Specifies that the column header should not /V Displays verbose task output. /TN taskname Specifies the task path\name for which /XML [xml_type] Displays task definitions in XML format. If xml_type is ONE then the output will be one valid XML file. If xml_type is not present then the output will be the concatenation of all XML task definitions. /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /Query /? 描述: 允许管理员显示本地或远程系统上的预定任务。 参数列表: /S system 指定要连接的远程系统。
示例: SCHTASKS /Query SCHTASKS /Query /? SCHTASKS /Query /S system /U user /P password SCHTASKS /Query /FO LIST /V /S system /U user /P password SCHTASKS /Query /FO TABLE /NH /V |
SCHTASKS /Change /? SCHTASKS /Change [/S system [/U username [/P [password]]]] /TN taskname Description: Parameter List: /U username Specifies the user context under which schtasks.exe /P [password] Specifies the password for the given user context. /TN taskname Specifies the path\name of the task to change. /RU username Changes the user name (user context) under which the /TR taskrun Specifies the new program that the /ST starttime Specifies the start time to run the task. The time /RI interval Specifies the repetition interval in /ET endtime Specifies the end time to run the task. The time /DU duration Specifies the duration to run the task. The time /K Terminates the task at the endtime or duration time. /SD startdate Specifies the first date on which the task runs. /ED enddate Specifies the last date when the task should run. /IT Enables the task to run interactively only if the /RL level Sets the Run Level for the job. Valid values are /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 /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /Change /? 描述: 参数列表: /U username 指定 schtasks.exe 应在哪个用户上下文中执行。 /P [password] 指定给定用户上下文的密码。如果省略,则会提示输入。 /TN taskname 指定要更改的任务的路径\名称。 /RU username 更改计划任务要运行的用户名(用户上下文)。对于系统账户,有效值为""、"NT AUTHORITY\SYSTEM"或"SYSTEM"。 /TR taskrun 指定计划任务将运行的新程序。 /ST starttime 指定任务运行的开始时间。时间格式为 HH:mm(24小时制),例如,14:30 表示下午2:30。 /RI interval 指定重复间隔时间(分钟)。有效范围:1 - 599940 分钟。 /ET endtime 指定任务结束运行的时间。时间格式为 HH:mm(24小时制),例如,14:50 表示下午2:50。 /DU duration 指定任务运行的持续时间。时间格式为 HH:mm。与 /ET 选项不适用。 /K 在结束时间或持续时间到达时终止任务。 /SD startdate 指定任务开始运行的第一个日期。格式为 yyyy/mm/dd。 /ED enddate 指定任务应该运行的最后一个日期。格式为 yyyy/mm/dd。 /IT 仅当 /RU 用户当前登录时,允许任务以交互方式运行。只有在用户登录时任务才会运行。 /RL level 设置作业的运行级别。有效值为 LIMITED 和 HIGHEST。默认情况下不更改。 /ENABLE 启用计划任务。 /DISABLE 禁用计划任务。 /Z 在最后一次运行后标记任务以删除。 /DELAY delaytime 指定触发器触发后延迟运行任务的等待时间。时间格式为 mmmm:ss。此选项仅适用于计划类型 ONSTART、ONLOGON、ONEVENT。 /HRESULT 为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。 /? 显示此帮助消息。 |
SCHTASKS /ShowSid /? SCHTASKS /ShowSid /TN taskname [/HRESULT] [/?] Description: Parameter List: /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /ShowSid /? 描述: 显示计划任务专用用户的 SID。 参数列表: /TN taskname 指定计划任务的路径\名称。
示例: SCHTASKS /ShowSid /? SCHTASKS /ShowSid /TN "\Backup\Start Backup" |
SCHTASKS /Delete /? SCHTASKS /Delete [/S system [/U username [/P [password]]]] Description: Parameter List: /U username Specifies the user context under /P [password] Specifies the password for the given /TN taskname Specifies the path\name of the task to delete. /F Forcefully deletes the task and suppresses /HRESULT For better diagnosability, the process exit code /? Displays this help message. Examples: |
SCHTASKS /Delete /? 描述: 删除一个或多个计划任务。 参数列表: /S system 指定要连接的远程系统。
示例: SCHTASKS /Delete /TN * /F SCHTASKS /Delete /TN "\Backup\Backup and Restore" SCHTASKS /Delete /S system /U user /P password /TN "\Backup\Start Restore" SCHTASKS /Delete /S system /U user /P password /TN "\Backup\Start Backup" /F |