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% 环境变量涉及到以下方面的基础技术:

  1. 环境变量:环境变量是操作系统中用来存储特定信息的动态值。它们对于配置和控制应用程序行为非常重要。

  2. 系统路径%systemroot% 在系统中被广泛使用,特别是在批处理脚本和命令行操作中。了解系统路径的设置和使用可以帮助管理和维护Windows系统。

  3. 操作系统结构%systemroot% 的存在反映了操作系统的结构设计,即将系统文件和核心组件存放在一个独立的目录中,便于管理和维护。

  4. 系统部署和管理:在系统部署和管理过程中,了解和利用 %systemroot% 变量可以帮助管理员更好地管理系统资源,并编写更具可移植性的脚本和配置。

总的来说,%systemroot% 环境变量涉及到操作系统的结构、环境变量的使用和系统管理等基础技术原理。


除了 %systemroot%,在Windows操作系统中还有一些其他常用的环境变量,它们在系统管理和应用程序开发中发挥着重要作用。以下是一些常见的Windows环境变量及其作用:

  1. %USERPROFILE%:指向当前用户的个人文件夹,通常为 C:\Users\用户名。这个变量可以帮助访问用户的个人文件和设置。

  2. %PATH%:包含一组目录路径,系统会在这些路径中查找可执行文件。通过将程序的可执行文件路径添加到 %PATH% 中,可以在命令行中直接执行该程序。

  3. %TEMP%%TMP%:分别指向用于存储临时文件的目录。程序可以使用这些变量来保存临时数据,并确保在不同系统上具有一致的行为。

  4. %PROGRAMFILES%%PROGRAMFILES(x86)%:分别指向安装的应用程序的默认目录。%PROGRAMFILES% 在64位系统上指向 C:\Program Files,而 %PROGRAMFILES(x86)% 则指向 C:\Program Files (x86)

  5. %SystemDrive%:指向系统安装所在的驱动器。通常为 C:,但在某些情况下可能会安装在其他驱动器上。

  6. %COMPUTERNAME%:指向计算机的名称,用于标识网络中的计算机。

  7. %USERNAME%:指向当前登录用户的用户名。

这些环境变量在Windows系统中被广泛使用,可以简化系统管理、脚本编写和应用程序开发过程中的路径和配置管理。


除了之前提到的环境变量之外,Windows操作系统还有一些其他常用的环境变量,它们在系统管理和应用程序开发中也都有各自的作用。以下是另外一些常见的Windows环境变量及其作用:

  1. %APPDATA%:指向当前用户的应用程序数据目录,通常为 C:\Users\用户名\AppData\Roaming。这个变量用于存储应用程序的设置和数据。

  2. %HOMEPATH%:指向当前用户的用户文件夹路径(不包括驱动器信息),通常为 \Users\用户名

  3. %LOGONSERVER%:指向处理当前登录请求的域控制器的名称。

  4. %OS%:指向当前操作系统的名称。

  5. %NUMBER_OF_PROCESSORS%%PROCESSOR_ARCHITECTURE%:分别指向系统中安装的处理器数量和处理器架构。

  6. %SystemRoot%:与 %systemroot% 类似,都指向Windows系统的安装目录。

  7. %TEMP%%TMP%:这两个变量也被广泛使用,它们分别指向用于存储临时文件的目录。

这些环境变量在Windows系统中起着重要的作用,能够简化系统配置、管理和应用程序开发过程中的路径和设置管理。通过合理利用这些环境变量,可以使系统更加灵活、可移植和易于管理。


Windows操作系统还有一些其他常用的环境变量。以下是另外一些常见的Windows环境变量及其作用:

  1. %ALLUSERSPROFILE%:指向所有用户共享的配置文件和数据的目录,通常为 C:\ProgramData

  2. %PUBLIC%:指向公共文件夹的路径,通常为 C:\Users\Public

  3. %COMSPEC%:指向命令解释器的可执行文件路径,默认为 C:\Windows\System32\cmd.exe

  4. %SystemDrive%%SystemRoot%%SystemDrive% 指向系统安装所在的驱动器,通常为 C:%SystemRoot% 则指向Windows系统目录,通常为 %SystemDrive%\Windows

  5. %ProgramData%:指向程序数据的默认存储位置,通常为 C:\ProgramData

  6. %CommonProgramFiles%%CommonProgramFiles(x86)%:分别指向用于存储共享程序文件的目录,通常为 C:\Program Files\Common FilesC:\Program Files (x86)\Common Files

  7. %USERDOMAIN%:指向当前用户所属的域名。


以下是另外一些常见的Windows环境变量及其作用:

  1. %USERDOMAIN_ROAMINGPROFILE%:指向用户域的漫游配置文件路径。

  2. %APPDATA%:指向当前用户的应用程序数据目录,通常为 C:\Users\用户名\AppData\Roaming。这个变量用于存储应用程序的设置和数据。

  3. %LOCALAPPDATA%:指向当前用户的本地应用程序数据目录,通常为 C:\Users\用户名\AppData\Local。这个变量用于存储应用程序的本地设置和数据。

  4. %PUBLIC%:指向公共文件夹的路径,通常为 C:\Users\Public。该变量用于访问公共文件夹中的内容。

  5. %USERPROFILE%:指向当前用户的个人文件夹,通常为 C:\Users\用户名。可以使用这个变量来访问用户的个人文件和设置。

  6. %SystemDrive%%SystemRoot%%SystemDrive% 指向系统安装所在的驱动器,通常为 C:%SystemRoot% 则指向Windows系统目录,通常为 %SystemDrive%\Windows

  7. %SESSIONNAME%:指示当前会话的名称。


SCHTASKS /parameter [arguments]

描述:
允许管理员在本地或远程系统上创建、删除、查询、更改、运行和结束定时任务。

参数列表:
/Create         创建新的定时任务。

/Delete         删除定时任务。

/Query          显示所有定时任务。

/Change         更改定时任务的属性。

/Run            按需运行定时任务。

/End            停止当前正在运行的定时任务。

/ShowSid        显示与定时任务名称对应的安全标识符。

/?              显示此帮助消息。
示例:
SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query  /?
SCHTASKS /Change /?
SCHTASKS /ShowSid /?

schtasks /create /?

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] [/?]

Description:
    Enables an administrator to create scheduled tasks on a local or
    remote system.

Parameter List:
    /S   system        Specifies the remote system to connect to. 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    idletime     Specifies the amount of idle time to wait before
                       running a scheduled ONIDLE task.
                       Valid range: 1 - 999 minutes.

    /TN   taskname     Specifies the string in the form of path\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 PM. Defaults to current time if /ST is not
                       specified.  This option is required with /SC ONCE.

    /RI   interval     Specifies the repetition interval in minutes. This 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 PM.
                       This 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. This 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.
                       This 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 yyyy/mm/dd. Defaults to the current
                       date. This 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 yyyy/mm/dd. This 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.

    /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 Run Level 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 diagnosability, the process exit code
                       will be in the HRESULT format.

    /?                 Displays this help message.

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.
    MONTHLY: 1 - 12, or
             FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.

    ONEVENT:  XPath event query string.
Examples:
    ==> Creates a scheduled task "doc" on the remote machine "ABC"
        which runs notepad.exe every hour under user "runasuser".

        SCHTASKS /Create /S ABC /U user /P password /RU runasuser
                 /RP runaspassword /SC HOURLY /TN doc /TR notepad

    ==> Creates a scheduled task "accountant" on the remote machine
        "ABC" to run calc.exe every five minutes from the specified
        start time to end time between the start date and end date.

        SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE
                 /MO 5 /TN accountant /TR calc.exe /ST 12:00 /ET 14:00
                 /SD 06/06/2006 /ED 06/06/2006 /RU runasuser /RP userpassword

    ==> Creates a scheduled task "gametime" to run freecell on the
        first Sunday of every month.

        SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime
                 /TR c:\windows\system32\freecell

    ==> Creates a scheduled task "report" on remote machine "ABC"
        to run notepad.exe every week.

        SCHTASKS /Create /S ABC /U user /P password /RU runasuser
                 /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe

    ==> Creates a scheduled task "logtracker" on remote machine "ABC"
        to run notepad.exe every five minutes starting from the
        specified start time with no end time. The /RP password will be
        prompted for.

        SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE
                 /MO 5 /TN logtracker
                 /TR c:\windows\system32\notepad.exe /ST 18:30
                 /RU runasuser /RP

    ==> Creates a scheduled task "gaming" to run freecell.exe starting
        at 12:00 and automatically terminating at 14:00 hours every day

        SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00
                 /ET 14:00 /K
    ==> Creates a scheduled task "EventLog" to run wevtvwr.msc starting
        whenever event 101 is published in the System channel

        SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT
                 /EC System /MO *[System/EventID=101]
    ==> Spaces in file paths can be used by using two sets of quotes, one
        set for CMD.EXE and one for SchTasks.exe.  The outer quotes for CMD
        need to be double quotes; the inner quotes can be single quotes or
        escaped double quotes:
        SCHTASKS /Create
           /tr "'c:\program files\internet explorer\iexplorer.exe'
           \"c:\log data\today.xml\"" ...

schtasks /create /?

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”也可用,以及三者的所有已知SIDs。

/RP  [password]    指定“作为”用户的密码。如需提示输入密码,值必须是“*”或无。此密码对于系统帐户无效。必须与/RU或/XML开关结合使用。

/SC   schedule     指定计划频率。
                   有效的计划类型:MINUTE、HOURLY、DAILY、WEEKLY、MONTHLY、ONCE、ONSTART、ONLOGON、ONIDLE、ONEVENT。

/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任务之前的空闲时间量。
                   有效范围:1-999分钟。

/TN   taskname     指定以路径\名称形式的字符串,唯一标识此定时任务。

/TR   taskrun      指定要在预定时间运行的程序的路径和文件名。
                   例如:C:\windows\system32\calc.exe

/ST   starttime    指定运行任务的开始时间。时间格式为HH:mm(24小时制),例如,14:30表示下午2:30。如果未指定/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。不适用于计划类型: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    指定任务运行的第一个日期。格式为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                创建一个对较早版本可见的任务。
                   与/XML不兼容。

/F                 强制创建任务,并抑制如果指定任务已存在时的警告。

/RL   level        设置作业的运行级别。有效值为LIMITED和HIGHEST。默认值为LIMITED。

/DELAY delaytime   指定触发器触发后运行任务的等待时间。时间格式为mmmm:ss。此选项仅适用于计划类型ONSTART、ONLOGON、ONEVENT。

/HRESULT           为了更好地诊断,进程退出代码将采用HRESULT格式。

/?                 显示此帮助消息。
修饰符:/MO开关针对每个调度类型的有效值:
MINUTE:  1 - 1439分钟。
HOURLY:  1 - 23小时。
DAILY:   1 - 365天。
WEEKLY:  第1周 - 第52周。
ONCE:    无修饰符。
ONSTART: 无修饰符。
ONLOGON: 无修饰符。
ONIDLE:  无修饰符。
MONTHLY: 1 - 12,或
FIRST、SECOND、THIRD、FOURTH、LAST、LASTDAY。

ONEVENT:  XPath事件查询字符串。
示例:
==> 在远程计算机“ABC”上创建一个名为“doc”的定时任务,每小时以“runasuser”用户身份运行notepad.exe。

    SCHTASKS /Create /S ABC /U user /P password /RU runasuser
             /RP runaspassword /SC HOURLY /TN doc /TR notepad

==> 在远程计算机“ABC”上创建一个名为“accountant”的定时任务,从指定的开始时间到结束时间每五分钟运行一次calc.exe,在指定的开始日期和结束日期之间运行。

    SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE
             /MO 5 /TN accountant /TR calc.exe /ST 12:00 /ET 14:00
             /SD 06/06/2006 /ED 06/06/2006 /RU runasuser /RP userpassword

==> 创建一个名为“gametime”的定时任务,在每个月的第一个星期日运行freecell。

    SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime
             /TR c:\windows\system32\freecell

==> 在远程计算机“ABC”上创建一个名为“report”的定时任务,每周运行notepad.exe。

    SCHTASKS /Create /S ABC /U user /P password /RU runasuser
             /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe

==> 在远程计算机“ABC”上创建一个名为“logtracker”的定时任务,每五分钟从指定的开始时间开始运行notepad.exe,没有结束时间。将提示输入/RP密码。

    SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE
             /MO 5 /TN logtracker
             /TR c:\windows\system32\notepad.exe /ST 18:30
             /RU runasuser /RP

==> 创建一个名为“gaming”的定时任务,每天从12:00开始运行freecell.exe,并在14:00自动终止。

    SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00
             /ET 14:00 /K

==> 创建一个名为“EventLog”的定时任务,当System通道中发布事件101时开始运行wevtvwr.msc。

    SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT
             /EC System /MO *[System/EventID=101]

==> 文件路径中的空格可以通过使用两组引号来实现,一组用于CMD.EXE,一组用于SchTasks.exe。CMD的外部引号需要是双引号;内部引号可以是单引号或转义双引号:
    SCHTASKS /Create
       /tr "'c:\program files\internet explorer\iexplorer.exe'
       \"c:\log data\today.xml\"" ...


SCHTASKS /Run /?

SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I]
         /TN taskname [/HRESULT] [/?]

Description:
    Runs a scheduled task on demand.

Parameter List:
    /S     system        Specifies the remote system to connect to.

    /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      Specifies the path\name of the task to run now.

    /HRESULT             For better diagnosability, the process exit code
                         will be in the HRESULT format.

    /?                   Displays this help message.

Examples:
    SCHTASKS /Run /?
    SCHTASKS /Run /TN "\Backup\Start Backup"
    SCHTASKS /Run /S system /U user /P password /I /TN "\Backup\Backup and Restore"

SCHTASKS /Run /?

描述:
在需求时立即运行一个预定任务。

参数列表:
/S     system        指定要连接的远程系统。

/U     username      指定 schtasks.exe 应在哪个用户上下文中执行。

/P     [password]    指定给定用户上下文的密码。如果省略,则会提示输入。

/I                   通过忽略任何约束条件立即运行任务。

/TN    taskname      指定要立即运行的任务的路径\名称。

/HRESULT             为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。

/?                   显示此帮助消息。
示例:
SCHTASKS /Run /?
SCHTASKS /Run /TN "\Backup\Start Backup"
SCHTASKS /Run /S system /U user /P password /I /TN "\Backup\Backup and Restore"

SCHTASKS /End /?

SCHTASKS /End [/S system [/U username [/P [password]]]]
         /TN taskname [/HRESULT] [/?]

Description:
    Stops a running scheduled task.

Parameter List:
    /S   system      Specifies the remote system to connect to.

    /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 path\name of the task to terminate.

    /HRESULT         For better diagnosability, the process exit code
                     will be in the HRESULT format.

    /?               Displays this help message.

Examples:
    SCHTASKS /End /?
    SCHTASKS /End /TN "\Backup\Start Backup"
    SCHTASKS /End /S system /U user /P password /TN "\Backup\Backup and Restore"

SCHTASKS /End /?

描述:
停止正在运行的预定任务。

参数列表:
/S   system      指定要连接的远程系统。

/U   username    指定 schtasks.exe 应在哪个用户上下文中执行。

/P   [password]  指定给定用户上下文的密码。如果省略,则会提示输入。

/TN  taskname    指定要终止的任务的路径\名称。

/HRESULT         为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。

/?               显示此帮助消息。
示例:
SCHTASKS /End /?
SCHTASKS /End /TN "\Backup\Start Backup"
SCHTASKS /End /S system /U user /P password /TN "\Backup\Backup and Restore"

 

SCHTASKS /Query  /?

SCHTASKS /Query [/S system [/U username [/P [password]]]]
         [/FO format | /XML [xml_type]] [/NH] [/V]
         [/TN taskname] [/HRESULT] [/?]

Description:
    Enables an administrator to display the scheduled tasks on the
    local or remote system.

Parameter List:
    /S    system         Specifies the remote system to connect to.

    /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
                         be displayed in the output. This is
                         valid only for TABLE and CSV format.

    /V                   Displays verbose task output.

    /TN   taskname       Specifies the task path\name for which
                         to retrieve the information, else all of them.

    /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
                         will be in the HRESULT format.

    /?                   Displays this help message.

Examples:
    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 /Query /?

描述: 允许管理员显示本地或远程系统上的预定任务。

参数列表: /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 /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
     { [/RU runasuser] [/RP runaspassword] [/TR taskrun] [/ST starttime]
       [/RI interval] [ {/ET endtime | /DU duration} [/K] ]
       [/SD startdate] [/ED enddate] [/ENABLE | /DISABLE] [/IT] [/Z] }
       [/HRESULT] [/?]

Description:
    Changes the program to run, or user account and password used
    by a scheduled task.

Parameter List:
    /S       system      Specifies the remote system to connect to.

    /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 path\name of the task to change.

    /RU      username    Changes the user name (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 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 will run.

    /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 PM.

    /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 PM.

    /DU      duration    Specifies the duration to run the task. The time
                         format is HH:mm. This 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 yyyy/mm/dd.

    /ED      enddate     Specifies the last date when the task should run.
                         The format is yyyy/mm/dd.

    /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.

    /RL      level       Sets the Run Level 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 diagnosability, the process exit code
                         will be in the HRESULT format.

    /?                   Displays this help message.

Examples:
    SCHTASKS /Change /RP password /TN "\Backup\Backup and Restore"
    SCHTASKS /Change /TR restore.exe /TN "\Backup\Start Restore"
    SCHTASKS /Change /S system /U user /P password /RU newuser
             /TN "\Backup\Start Backup" /IT

SCHTASKS /Change /?

描述:
更改要运行的程序,或计划任务使用的用户账户和密码。

参数列表:
/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。

/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 /Change /RP password /TN "\Backup\Backup and Restore"
SCHTASKS /Change /TR restore.exe /TN "\Backup\Start Restore"
SCHTASKS /Change /S system /U user /P password /RU newuser
/TN "\Backup\Start Backup" /IT

 

SCHTASKS /ShowSid /?

SCHTASKS /ShowSid /TN taskname [/HRESULT] [/?]

Description:
    Shows the SID for the task's dedicated user.

Parameter List:
    /TN  taskname    Specifies the path\name of the scheduled task.

    /HRESULT         For better diagnosability, the process exit code
                     will be in the HRESULT format.

    /?               Displays this help message.

Examples:
    SCHTASKS /ShowSid /?
    SCHTASKS /ShowSid /TN "\Backup\Start Backup"

SCHTASKS /ShowSid /?

描述: 显示计划任务专用用户的 SID。

参数列表:

/TN taskname 指定计划任务的路径\名称。

/HRESULT             为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。

/?                   显示此帮助消息。

示例:

SCHTASKS /ShowSid /?

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

SCHTASKS /Delete /?

SCHTASKS /Delete [/S system [/U username [/P [password]]]]
         /TN taskname [/F] [/HRESULT] [/?]

Description:
    Deletes one or more scheduled tasks.

Parameter List:
    /S   system         Specifies the remote system to connect to.

    /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 path\name of the 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 diagnosability, the process exit code
                        will be in the HRESULT format.

    /?                  Displays this help message.

Examples:
    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

SCHTASKS /Delete /?

描述: 删除一个或多个计划任务。

参数列表:

/S system 指定要连接的远程系统。

/U       username    指定 schtasks.exe 应在哪个用户上下文中执行。

/P       [password]  指定给定用户上下文的密码。如果省略,则会提示输入。

/TN      taskname    指定要删除的任务的路径\名称。
                    可以使用通配符 "*" 来删除所有任务。

/F                   强制删除任务,并且如果指定的任务当前正在运行,则抑制警告。

/HRESULT             为了更好的诊断能力,进程退出代码将以 HRESULT 格式显示。

/?                   显示此帮助消息。

示例:

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

posted @ 2024-03-23 22:10  suv789  阅读(247)  评论(0编辑  收藏  举报