在 win 7 任务计划程序中顺序运行批处理文件
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以使用适用于 Windows 7、Windows Server 2008 R2、Windows Server 2012、Windows Vista 的 Windows 计划任务。
来自 Microsoft 文档:
It's possible using Windows Scheduled Tasks for Windows 7, Windows Server 2008 R2, Windows Server 2012, Windows Vista.
From Microsoft documentation:
我相信解决此问题的最简单方法是让第一个批处理文件调用第二个批处理文件。由于批处理文件中的命令是按顺序处理的,因此可以解决您的问题。
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.
另一种方法是让操作包含
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.