在 win 7 任务计划程序中顺序运行批处理文件

发布于 2024-10-07 08:02:32 字数 490 浏览 3 评论 0原文

我有 2 个批处理文件作为单个任务中的“操作”。第一个使用 Microsoft Security Essentials 扫描病毒。第二个让计算机进入睡眠状态。问题是,当任务运行时,似乎两个批处理文件同时运行,也就是说,我可以看到病毒扫描的开始,但随后计算机几乎立即进入睡眠状态,因此扫描实际上永远没有机会开始。我知道批处理文件将在任务计划程序中按顺序运行。我错了吗?如何使睡眠批处理文件等待扫描批处理文件完成?这是 2 个简单的批处理文件...

批处理文件一

"C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe" -scan -scantype 1

批处理文件二

powercfg -h off

rundll32.exe powrprof.dll,SetSuspendState 0,1,0

powercfg -h on

I have 2 batch files as "actions" in a single task. The first one does a scan for viruses using microsoft security essentials. The second one puts the computer to sleep. The problem is that when the task is run, it seems like both batch files run simultaneously, that is, I can see the start of the virus scan, but then the computer goes to sleep almost immediately, so the scan really never has a chance to start. I understood that batch files would run in sequential order in the task scheduler. Am I wrong? How do I make the sleep batch file wait until the scan batch file has completed? Here are the 2 simple batch files...

Batch file one

"C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe" -scan -scantype 1

Batch file two

powercfg -h off

rundll32.exe powrprof.dll,SetSuspendState 0,1,0

powercfg -h on

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡墨 2024-10-14 08:02:32

可以使用适用于 Windows 7、Windows Server 2008 R2、Windows Server 2012、Windows Vista 的 Windows 计划任务。

来自 Microsoft 文档

任务操作是任务运行时执行的工作。一个任务可以有一个操作或最多 32 个操作。每个操作都包含确定操作如何执行的设置。任务的操作显示在“任务属性”或“创建任务”对话框的“操作”选项卡上。 指定多个操作时,它们会按顺序执行,从“操作”选项卡中列表顶部的操作开始...

It's possible using Windows Scheduled Tasks for Windows 7, Windows Server 2008 R2, Windows Server 2012, Windows Vista.

From Microsoft documentation:

A task action is the work that is performed when the task is run. A task can have a single action or a maximum of 32 actions. Each action contains settings that determine how the action is performed. A task's actions are displayed on the Actions tab of the Task Properties or Create Task dialog box. When multiple actions are specified, they are executed in sequential order starting with the action at the top of the list in the Actions tab...

妄断弥空 2024-10-14 08:02:32

我相信解决此问题的最简单方法是让第一个批处理文件调用第二个批处理文件。由于批处理文件中的命令是按顺序处理的,因此可以解决您的问题。

I believe the easiest way to fix this is to have the first batch file call the second batch file. Since the commands in batch files are processed sequentially that would fix your problem.

初见你 2024-10-14 08:02:32

另一种方法是让操作包含 START /WC:\MyScript.bat /W 是启动命令在返回控制之前等待完成的参数。

Another way is for the action to contain START /W C:\MyScript.bat The /W is a parameter for the start command to wait for completion before returning control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文