等待程序完成 [英] Wait for program to complete

查看:40
本文介绍了等待程序完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了监控带宽使用情况而不是在启动时不必要地加载程序,我想执行dumeter.exe然后firefox.exe.当我关闭firefox时它应该杀死dumeter.我使用以下代码启动

To monitor the bandwidth usage and not to unnecessarily load programs in the start up,I want to execute the dumeter.exe then firefox.exe.When I shutdown firefox it should kill dumeter.I used the following code to start

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\progra~1\dumeter\dumeter.exe"
WshShell.Run "c:\progra~1\mozill~1\firefox.exe

仅在关闭 firefox 时才需要运行 taskkill.尝试使用 bat 文件,但有时 dumeter 自行启动和关闭不会等待.

Need to run taskkill only when firefox is closed.Tried using a bat file but sometimes the dumeter starts and closes on its own does not wait.

 WshShell.Run "taskkill /f /im dumeter.exe"  
 Set WshShell = Nothing

推荐答案

您可以通过订阅适当的 WMI 事件来等待进程结束.举个例子:

You can wait for a process to end by subscribing to the appropriate WMI event. Here's an example:

strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

''# Create an event query to be notified within 5 seconds when Firefox is closed
Set colEvents = oWMI.ExecNotificationQuery _
    ("SELECT * FROM __InstanceDeletionEvent WITHIN 5 " _
     & "WHERE TargetInstance ISA 'Win32_Process' " _
     & "AND TargetInstance.Name = 'firefox.exe'")

''# Wait until Firefox is closed
Set oEvent = colEvents.NextEvent

更多信息:如何启动一个进程,然后等待进程结束再终止脚本?

这篇关于等待程序完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆