您可以將進程分配給一個變量,並等待它退出:
Private Sub login(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim ieproc As Process
ieproc = Process.Start("iexplore.exe")
ieproc.WaitForInputIdle()
ieproc.WaitForExit() '<= processing will wait here until the browser is closed
MsgBox("IE has closed!")
End sub
或者,如果你不想停止處理,不要使用WaitForExit
,而是使用後臺進程或定時定期檢查過程已經結束......這裏是一個使用計時器一個簡單的例子:
Dim ieproc As Process
Private Sub login(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
ieproc = Process.Start("iexplore.exe")
ieproc.WaitForInputIdle()
Timer1.Enabled = True
End sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If ieproc.HasExited Then
Me.Timer1.Enabled = False
MsgBox("IE has closed!")
End If
End Sub
的邏輯是好了,但是我還沒有收我的互聯網瀏覽器,它已經顯示出我的消息「IE已經關閉」。我想要的只是當我關閉瀏覽器時,提示信息將顯示。 – PACMAN
使用WaitForExit或Timer的方法?我只測試了兩個,他們的工作。瀏覽器關閉前沒有消息框。 –
嘗試添加'ieproc.WaitForInputIdle()'...看到我上面更新的代碼。 –