如何以编程方式在远程计算机上停止/启动计划任务?

Ben*_*and 51 windows scheduled-tasks

我想编写一个脚本,它将停止远程计算机上的计划任务,执行一些操作,然后启动计划任务备份.

我该怎么做?

Ben*_*and 100

这是我发现的.

停:

schtasks /end /s <machine name> /tn <task name>
Run Code Online (Sandbox Code Playgroud)

开始:

schtasks /run /s <machine name> /tn <task name>


C:\>schtasks /?

SCHTASKS /parameter [arguments]

Description:
    Enables an administrator to create, delete, query, change, run and
    end scheduled tasks on a local or remote system. Replaces AT.exe.

Parameter List:
    /Create         Creates a new scheduled task.

    /Delete         Deletes the scheduled task(s).

    /Query          Displays all scheduled tasks.

    /Change         Changes the properties of scheduled task.

    /Run            Runs the scheduled task immediately.

    /End            Stops the currently running scheduled task.

    /?              Displays this help message.

Examples:
    SCHTASKS
    SCHTASKS /?
    SCHTASKS /Run /?
    SCHTASKS /End /?
    SCHTASKS /Create /?
    SCHTASKS /Delete /?
    SCHTASKS /Query  /?
    SCHTASKS /Change /?
Run Code Online (Sandbox Code Playgroud)

  • 机器名称是可选的:`schtasks /end /tn &lt;任务名称&gt;` (2认同)

Mat*_*son 5

注意: “schtasks”(请参阅另一个已接受的回复)已替换“at”。但是,如果情况要求与没有 schtasks 的旧版 Windows 兼容,则“at”可能有用。

“at”的命令行帮助:

C:\> 在 /?
AT 命令调度命令和程序在计算机上运行
指定的时间和日期。Schedule 服务必须正在运行才能使用
AT 命令。

AT [\\计算机名] [ [id] [/DELETE] | /删除[/是]]
在 [\\计算机名] 时间 [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "命令"

\\computername 指定远程计算机。命令被安排在
                   如果省略此参数,则为本地计算机。
id 是分配给预定的标识号
                   命令。
/delete 取消预定的命令。如果省略 id,则所有
                   计算机上的预定命令被取消。
/yes 与取消所有作业命令一起使用
                   需要确认。
time 指定命令运行的时间。
/interactive 允许作业与用户的桌面交互
                   谁在作业运行时登录。
/every:date[,...] 在一周的每个指定日期运行命令或
                   月。如果省略日期,则为当月的当前日期
                   假设。
/next:date[,...] 在下一次出现时运行指定的命令
                   天(例如,下周四)。如果省略日期,则
                   假定为当月的当前日期。
“命令”是 Windows NT 命令,或要运行的批处理程序。