命令行创建任务计划_如何从命令行创建,修改和删除计划任务

命令行创建任务计划

命令行创建任务计划

Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.

Windows XP / Server 2003向我们介绍了SchTasks命令行工具,该工具取代了Windows 2000中提供的At工具。此工具提供了通过调用此命令来控制计划任务的各个方面的功能。

While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:

Windows使用向导来帮助您以图形方式创建计划任务非常好,但是命令行工具非常适合以下情况:

  • Manipulate tasks in batch scripts.

    在批处理脚本中处理任务。
  • Control and create tasks on networked machines without having to login to them.

    在联网的计算机上控制和创建任务,而无需登录。
  • Mass create/sync task across multiple machines.

    在多台计算机上批量创建/同步任务。
  • Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.

    在自定义应用程序中使用,可以与Task Scheduler通信,而不必进行API调用。

As you can probably imagine, the SchTasks command has more options than we can cover in this article so we are going to focus on showing some examples of common task configurations and what the respective task looks like in the Task Scheduler.

您可能会想到,SchTasks命令具有比本文更多的选项,因此我们将重点介绍一些常见任务配置的示例以及相应任务在Task Scheduler中的外观。

例子 (Examples)

创建“我的任务”以每天早上9点运行C:RunMe.bat: (Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:)

SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00

SchTasks /创建/ SC DAILY / TN“我的任务” /TR“C:RunMe.bat”/ST 09:00

image
image

修改“我的任务”以使其在下午2点运行: (Modify ‘My Task’ to run at 2 PM:)

SchTasks /Change /TN “My Task” /ST 14:00

SchTasks /更改/ TN“我的任务” / ST 14:00

image
image

创建“我的任务”以在每月的第一天运行C:RunMe.bat: (Create ‘My Task’ to run C:RunMe.bat on the first of every month:)

SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

SchTasks /创建/ SC MONTHLY / D 1 / TN“我的任务” / TR“ C:RunMe.bat” / ST 14:00

image
image

创建“我的任务”以在每个工作日的下午2点运行C:RunMe.bat: (Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:)

SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

SchTasks /创建/ SC每周/ D MON,TUE,WED,THU,FRI / TN“我的任务” / TR“ C:RunMe.bat” / ST 14:00

image
image

删除名为“我的任务”的任务: (Delete the task named ‘My Task’:)

SchTasks /Delete /TN “My Task”

SchTasks /删除/ TN“我的任务”

image

Note: this will raise a warning which you will need to confirm.

注意:这将引发警告,您需要确认。

批量创建 (Bulk Creation)

Like any other command line tool, you can include multiple instructions in a batch file to accomplish bulk creation (or deletion).

与其他任何命令行工具一样,您可以在批处理文件中包含多个指令以完成批量创建(或删除)。

For example, this script:

例如,此脚本:

SchTasks /Create /SC DAILY /TN “Backup Data” /TR “C:Backup.bat” /ST 07:00SchTasks /Create /SC WEEKLY /D MON /TN “Generate TPS Reports” /TR “C:GenerateTPS.bat” /ST 09:00SchTasks /Create /SC MONTHLY /D 1 /TN “Sync Database” /TR “C:SyncDB.bat” /ST 05:00

SchTasks /创建/ SC每日/ TN“备份数据” / TR“ C:Backup.bat” / ST 07:00SchTasks / Create / SC每周/ D MON / TN“生成TPS报告” / TR“ C:GenerateTPS.bat” / ST 09:00SchTasks /创建/ SC MONTHLY / D 1 / TN“同步数据库” / TR“ C:SyncDB.bat” / ST 05:00

Produces these tasks:

产生以下任务:

image

The ability to do this is a quick way to roll out new tasks or change existing schedules to many machines at once. As a way to ensure the tasks are updated, you could include the appropriate SchTasks commands in a domain login script which will update user machines when they log in.

执行此功能是一次快速推出新任务或将现有计划更改为多台计算机的快速方法。 为了确保更新任务,可以在域登录脚本中包含适当的SchTasks命令,该命令将在用户计算机登录时更新它们。

Microsoft Documentation on SchTasks Command

关于SchTasks命令的Microsoft文档

翻译自: https://www.howtogeek.com/51236/how-to-create-modify-and-delete-scheduled-tasks-from-the-command-line/

命令行创建任务计划

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值