如何以编程方式停止/启动远程计算机上的计划任务?
我想编写一个脚本来停止远程计算机上的计划任务,执行一些操作,然后重新启动计划任务。
我该怎么做?
这是我发现的。
停止:
schtasks /end /s <machine name> /tn <task name>
开始:
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 /?
注意: “schtasks” (见另一个被接受的答复)已经被replace为“at” 。 但是,如果情况要求与不具有schtasks的较旧版本的Windows兼容,则“at”可能是有用的。
“at”的命令行帮助:
C:\> at /?
AT命令安排命令和程序在计算机上运行
指定的时间和date。 Schedule服务必须运行才能使用
AT命令。
AT [\\ computername] [[id] [/ DELETE] | / DELETE [/ YES]]
AT [\\ computername]时间[/ INTERACTIVE]
[/ EVERY:date [,...] | / NEXT:date [,...]]“command”
\\ computername指定一台远程计算机。 命令安排在
本地计算机,如果这个参数被省略。
id是分配给预定的识别号码
命令。
/删除取消预定的命令。 如果id被省略,所有的
计算机上的预定命令被取消。
/ yes用于在不再继续时取消所有作业命令
需要确认。
时间指定命令运行的时间。
/ interactive允许作业与用户的桌面交互
谁在作业运行时login。
/ every:date [,...]在一周或每周的指定date运行命令
月。 如果date被忽略,则是当月的当天
假设。
/ next:date [,...]在下一次出现的地方运行指定的命令
日(例如下周四)。 如果date被省略,
假设当月的当天。
“命令”是Windows NT命令或批处理程序运行。
什么/disable ,和/enable切换一个/change命令?
schtasks.exe /change /s <machine name> /tn <task name> /disable schtasks.exe /change /s <machine name> /tn <task name> /enable
schtasks / change / disable / tn“任务名称”/ s REMOTEMACHINENAME / u mydomain \ administrator / p adminpassword