windows 如何通过命令行创建计划任务,其中包括高级选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3016452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create a scheduled task, via command line, which includes advanced options
提问by David Weiser
I'm trying to create a scheduled task (in WinXP) which runs every 10 minutes, starting at 16:00:00 to 06:00:00, daily, from the command line.
我正在尝试从命令行创建一个计划任务(在 WinXP 中),它每 10 分钟运行一次,从每天 16:00:00 到 06:00:00 开始。
Currently, I can create a scheduled task which runs every 10 minutes, starting at 16:00:00, daily, by using the following command:
目前,我可以使用以下命令创建一个计划任务,该任务每 10 分钟运行一次,从每天 16:00:00 开始:
SCHTASKS.EXE /CREATE /SC MINUTE /MO 10 /TN "Scheduled task name" /ST 16:00:00 /SD 01/01/2000 /TR task.bat /RU SYSTEM
The question is, how do I modify the previous command so that it stops running at 06:00:00?
问题是,如何修改上一个命令,使其在 06:00:00 停止运行?
回答by Robert Harvey
Since there doesn't appear to be a command line switch for the stop time of a particular task, I think the best you can do is try setting up a task for the allotted time that executes this:
由于似乎没有针对特定任务的停止时间的命令行开关,我认为您能做的最好的事情是尝试为执行此操作的分配时间设置一个任务:
schtasks /delete /tn "My Task"
which should remove the task from the task scheduler, and cause it to stop executing. I haven't tried this myself, so I don't know if it kills kittens or not.
这应该从任务调度程序中删除任务,并使其停止执行。这个我自己没试过,不知道会不会死猫。
回答by user1366521
schtasks /change ... /disable can do this for Vista/7/2003. xp does not support /disable the task definitions reside in C:\WINDOWS\Tasks with the ".job" file extension if you rename a ".job" file to something else such as ".bozo" it will not run you can name it back to ".job" to restart it.
schtasks /change ... /disable 可以为 Vista/7/2003 执行此操作。xp 不支持/禁用驻留在 C:\WINDOWS\Tasks 中的带有“.job”文件扩展名的任务定义,如果您将“.job”文件重命名为“.bozo”等其他内容,它将无法运行,您可以命名它回到“.job”以重新启动它。
回答by David Weiser
After much searching, I could find no way to modify the scheduled task from the command line. As a work around, I pushed the responsibility of running the program every 10 minutes to my executable, leaving the scheduled task the sole responsibility of kicking off the program daily.
经过多次搜索,我找不到从命令行修改计划任务的方法。作为一种解决方法,我将每 10 分钟运行一次程序的责任推给了我的可执行文件,让计划任务每天启动程序的唯一责任。