windows 任务计划程序如何运行多个 exe 实例?

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

How can Task Scheduler run multiple instances of the exe?

windowsscheduled-tasks

提问by Led

How can Task Scheduler run multiple instances of the exe? Let's say I have a daily schedule to open notepad.exe I hope each day will open a new one, instead it will only open the first one.

任务计划程序如何运行多个 exe 实例?假设我有一个每日计划来打开 notepad.exe 我希望每天都会打开一个新的,而不是只打开第一个。

If I first schdule run a .bat to run the exe, a console window will appear briefly, then I need some way to not show any console window.

如果我首先计划运行 .bat 来运行 exe,则会短暂出现一个控制台窗口,然后我需要某种方式来不显示任何控制台窗口。

Please help

请帮忙

回答by Dave

What OS are you trying this on? I tested this on Windows Server 2008 R2 using your notepad.exe example (no .cmd, just launching notepad.exe). If I set the option in the task Settings "If the task is already running, then the following rule applies:" >> Run a new instance in parallel.

你在什么操作系统上尝试这个?我使用您的 notepad.exe 示例(没有 .cmd,只需启动 notepad.exe)在 Windows Server 2008 R2 上对此进行了测试。如果我在任务设置中设置选项“如果任务已经在运行,则适用以下规则:”>> 并行运行新实例。

If I select this option then a new notepad.exe launches each time the scheduled task runs, otherwise only the first one launches it.

如果我选择此选项,则每次计划任务运行时都会启动一个新的 notepad.exe,否则只有第一个启动它。

/edit:

/编辑:

For Windows XP, you could launch the executable from another process that will exit. As Ryan mentioned, you could use a .cmd batch file and the START command. If you don't want the user that's logged in to see it run, you could set the task to run as NT AUTHORITY\SYSTEM

对于 Windows XP,您可以从将退出的另一个进程启动可执行文件。正如 Ryan 所说,您可以使用 .cmd 批处理文件和 START 命令。如果您不希望登录的用户看到它运行,您可以将任务设置为作为 NT AUTHORITY\SYSTEM 运行

回答by Ryan Bemrose

If you batch file is authored correctly, then the console window should only show up for a fraction of a second, and then disappear.

如果您正确编写了批处理文件,则控制台窗口应该只显示几分之一秒,然后消失。

start notepad myfirstfile.txt
start notepad mysecondfile.txt
exit /B 0

This shouldn't be a problem, especially since the main reason for a scheduled task is to run things when nobody's watching the computer.

这应该不是问题,特别是因为计划任务的主要原因是在没有人看计算机时运行一些东西。

If the momentary appearance of console windows is truly an unsightly crime against nature, then you need a solution which doesn't create a console window. See this superuser threadfor some scripting suggestions.

如果控制台窗口的瞬间出现确实是对自然的一种难看的犯罪,那么您需要一个不创建控制台窗口的解决方案。请参阅此超级用户线程以获取一些脚本建议。

Alternatively, since stackoverflow users are programmers, you can just write a very simple .exe which does what you want:

或者,由于 stackoverflow 用户是程序员,您可以编写一个非常简单的 .exe 来执行您想要的操作:

int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
   ShellExecute(NULL, NULL, "c:\windows\notepad.exe", "myfirstfile.txt", NULL, SW_SHOWDEFAULT);
   ShellExecute(NULL, NULL, "c:\windows\notepad.exe", "mysecondfile.txt", NULL, SW_SHOWDEFAULT);
   return 0;
}