Chris Chris - 1 year ago 96
Bash Question

VB6: How to wait for a command to execute

The code I have below runs without error.

But I need it to wait until the process has been killed at this line:

WshShell.Exec "TASKKILL /F /IM " & EngineRun.ProcessID
before showing the msgbox that it has been terminated.

Option Explicit

Dim WshShell As Object
Dim EngineRun As Object

Sub main()

Set WshShell = CreateObject("WScript.Shell")
Set EngineRun = WshShell.Exec("notepad.exe")

MsgBox EngineRun.ProcessID

WshShell.Exec "TASKKILL /F /IM " & EngineRun.ProcessID

MsgBox EngineRun.ProcessID & (" terminated")

End Sub

Thanks for any help

Answer Source

Could you use the Run method instead? See MSDN. It supports a bWaitOnReturn parameter:

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 

So your code would look like:

WshShell.Exec "TASKKILL /F /IM " & EngineRun.ProcessID,4 , True
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download