使用 Windows 任务计划程序每 x 分钟运行一次任务

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

Run a task every x-minutes with Windows Task Scheduler

windowsscheduled-tasks

提问by kacalapy

I'm trying to get Windows Task Scheduler to run a particular .exe every 10 minutes or so, but the options only allow for once a day execution.

我试图让 Windows 任务计划程序每 10 分钟左右运行一次特定的 .exe,但这些选项只允许每天执行一次。

Is there a way I can get it to run a .exe every 10 or 20 minutes?

有没有办法让它每 10 或 20 分钟运行一次 .exe?

回答by Coincoin

The task must be configured in two steps.

必须分两步配置任务。

First you create a simple task that start at 0:00, every day. Then, you go in Advanced...(or similar depending on the operating system you are on) and select the Repeat every X minutesoption for 24 hours.

首先,您创建一个简单的任务,每天从 0:00 开始。然后,您进入Advanced...(或类似,取决于您使用的操作系统)并选择Repeat every X minutes24 小时选项。

The key here is to find the advanced properties. If you are using the XP wizard, it will only offer you to launch the advanced dialog once you created the task.

这里的关键是找到高级属性。如果您使用 XP 向导,它只会在您创建任务后提供启动高级对话框。

On more recent versions of Windows (7+ I think?):

在更新版本的 Windows 上(我认为是 7+?):

  1. Double click the task and a property window will show up.
  2. Click the Triggerstab.
  3. Double click the trigger details and the Edit Trigger window will show up.
  4. Under Advanced settingspanel, tick Repeat task everyxxx minutes, and set Indefinitelyif you need.
  5. Finally, click ok.
  1. 双击任务,将出现一个属性窗口。
  2. 单击Triggers选项卡。
  3. 双击触发器详细信息,将显示“编辑触发器”窗口。
  4. Advanced settings面板下,勾选Repeat task everyxxx 分钟,并Indefinitely根据需要进行设置。
  5. 最后点击确定。

回答by Durim Sinani

After you select the minimum repeat option (5 minutes or 10 minutes) you can highlight the number and write whatever number you want

选择最少重复选项(5 分钟或 10 分钟)后,您可以突出显示数字并写下您想要的任何数字

回答by Kevin Lee

You can also create a batch file like the following if you need finer granularity between calls:

如果您在调用之间需要更精细的粒度,您还可以创建如下所示的批处理文件:

:loop
CallYour.Exe
timeout /t timeToWaitBetweenCallsInSeconds /nobreak
goto :loop

回答by Henrik

In the "Repeat Task every:" just type 2 minutes instead of choosing from the dropdown list.

在“重复任务间隔:”中只需输入 2 分钟,而不是从下拉列表中进行选择。

回答by Courtney Christensen

On XP, I clicked the Advancedbutton on the Scheduletab. There is a checkbox for Repeat task. The default is every 10 minutes.

在 XP 上,我单击AdvancedSchedule选项卡上的按钮。有一个复选框Repeat task。默认为每 10 分钟一次。

Additionally, you can create scheduled task via the command line. I haven't tried this myself, but it looks like you'd want something along the lines of (not tested):

此外,您可以通过命令行创建计划任务。我自己没有试过这个,但看起来你想要一些类似(未经测试)的东西:

schtasks /create /tn "Some task name" /tr "app.exe" /sc HOURLY 

回答by Mike Cush

Hourly task example

每小时任务示例

While taking the advice above with schtasks, you can see in the UI what must be done to perform an hourly task. When you edit trigger begin the task on a schedule, One Time (this is the key). Then you can select "Repeat task every:" 1 hour or whatever you wish. See screenshot:

在使用 schtasks 接受上述建议时,您可以在 UI 中看到执行每小时任务必须执行的操作。当您编辑触发器时,按计划开始任务,一次(这是关键)。然后您可以选择“重复任务间隔:”1 小时或您希望的任何时间。看截图:

回答by David

To schedule the update to be automatic you should:

要将更新安排为自动,您应该:

  • Go to Control Panel ? Administrative Tools ? Scheduled Tasks
  • Create the (basic) task
  • Go to Schedule ? Advanced
  • Check the box for "Repeat Task" every 10 minutes with a duration of, e.g. 24 hours or Indefinitely
  • Leave End Date unchecked
  • 进入控制面板?管理工具 ?计划任务
  • 创建(基本)任务
  • 转到日程表?先进的
  • 每 10 分钟选中一次“重复任务”框,持续时间为,例如 24 小时或无限期
  • 取消选中结束日期

If you cannot find the Schedule settings, look under: Properties, Edit, Triggers.

如果找不到计划设置,请查看:属性、编辑、触发器。

回答by MorningZ

Some of the links provided are onlysettings for Windows 2003's version of "Scheduled Tasks"

提供的一些链接只是Windows 2003 版本“计划任务”的设置

In Windows Server 2008 the "Tasks" setup onlyhas a box with options for "5 Minutes, 10 minutes, 15 minutes, 30 mins, and 1 hour" (screen shot: http://i46.tinypic.com/2gwx7r8.jpg)... where the Window 2003 was a "enter whatever number you want" textbox.

在 Windows Server 2008 中,“任务”设置只有一个框,其中包含“5 分钟、10 分钟、15 分钟、30 分钟和 1 小时”选项(屏幕截图:http: //i46.tinypic.com/2gwx7r8.jpg)... Window 2003 是一个“输入任何你想要的数字”文本框。

I thought doing an "Export" and editing the XML from: PT30M to PT2M

我想做一个“导出”并编辑 XML 从:PT30M 到 PT2M

and importing that as a new task would "trick" Tasks into repeating every 2 mins, but it didn't like that

并将其作为新任务导入会“欺骗”任务每 2 分钟重复一次,但它不喜欢那样

My workaround for getting a task to run every 2 mins in Windows 2008 was to (ugggh) setup 30 different "triggers" for my task repeating every hour but staring at :00, :02, :04, :06 and so on and so on.... took me 8-10 mins to setup but I only had to do it once :-)

我在 Windows 2008 中让任务每 2 分钟运行一次的解决方法是 (ugggh) 为我的任务设置 30 个不同的“触发器”,每小时重复一次,但盯着 :00、:02、:04、:06 等等上....花了我 8-10 分钟来设置,但我只需要做一次:-)