Windows 7 计划任务命令行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19641619/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:01:38  来源:igfitidea点击:

Windows 7 Scheduled task command line

windowsscheduled-tasks

提问by user1444886

This command should create a task that every minute runs the calculator windows application.

此命令应创建一个每分钟运行计算器 Windows 应用程序的任务。

schtasks /Create /tn "mytask" /sc MINUTE /mo 1  /ru "myuser" /rp "mypassword" /tr "C:\Windows\System32\calc.exe"

It runs OK, the tasks gets added. The task looks right. The tasks shows as started in the schedular but the calculator does not get fired up. The exe exists, I can run it separately.

它运行正常,任务被添加。任务看起来不错。任务在计划中显示为已开始,但计算器并未启动。exe存在,我可以单独运行它。

Anyone know why I don't see the calculator?

有谁知道为什么我看不到计算器?

采纳答案by Eric Brown

Probably because the task isn't running interactively. Add the '/it' option:

可能是因为该任务未以交互方式运行。 添加“/it”选项

/IT
A value that enables the task to run interactively only if the /RU user is currently logged on at the time the task runs. The task runs only if the user is logged on.

/IT
一个值,仅当 /RU 用户在任务运行时当前已登录时,该值才能使任务以交互方式运行。该任务仅在用户登录时运行。

Without the /it option, tasks run in session 0, which doesn't allow interaction with the user. For more information, do a web search for "Session 0 isolation".

如果没有 /it 选项,任务将在不允许与用户交互的会话 0 中运行。有关更多信息,请在网络上搜索“会话 0 隔离”。

回答by Sudhakar

How to Create, Modify and Delete Scheduled Tasks from the Command Line 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.

在批处理脚本中操作任务。无需登录即可在联网机器上控制和创建任务。跨多台机器批量创建/同步任务。在自定义应用程序中使用以与任务计划程序进行通信,而不必进行 API 调用。

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

例如:创建“我的任务”以每天上午 9 点运行 C:RunMe.bat: SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00

Modify ‘My Task' to run at 2 PM: SchTasks /Change /TN “My Task” /ST 14:00

将“我的任务”修改为在下午 2 点运行: SchTasks /Change /TN “My Task” /ST 14:00

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

创建“我的任务”以在每个月的第一天运行 C:RunMe.bat: SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

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

创建“我的任务”以在每个工作日的下午 2 点运行 C:RunMe.bat: SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

Delete the task named ‘My Task': SchTasks /Delete /TN “My Task”

删除名为“我的任务”的任务: SchTasks /Delete /TN “My Task”