tags:

views:

17

answers:

1

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

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
+1  A: 

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

More info here: How Can I Start a Process and Then Wait For the Process to End Before Terminating the Script?

Helen