Hello,
I have one scenario with opening, activating and closing a project which don't work.
Here are two declarations on form level:
Then with menu item I started a proccess:
And in the FormClosing event handler...
Idea is to prevent to open explorer window more than once.
And to close it after usage or at least at exit.
As I can see:
Please any help to get this working.
I have one scenario with opening, activating and closing a project which don't work.
Here are two declarations on form level:
Code:
Dim explorerID As Integer = 0
Dim eProc As Process = NothingCode:
If explorerID > 0 Then ' if i have previous proccess ID
Try
AppActivate(explorerID) ' try to activate
Catch
eProc.Dispose() ' if can't activate a proccess dispose it
eProc = Nothing ' and set proccessID to 0
explorerID = 0
End Try
End If
If explorerID = 0 Then ' if I havent proccess ID (or it is cleared by previous code)
eProc = New Process 'start a new proccess
With eProc.StartInfo
.FileName = "explorer.exe"
.Arguments = myPath
.WindowStyle = ProcessWindowStyle.Normal
End With
eProc.Start()
explorerID = eProc.Id 'take a new proccess ID
End IfCode:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
KillExplorer() 'kill procces before exit if it exists
End Sub
Private Sub KillExplorer()
If explorerID > 0 Then ' if my proccess is opened
Try
eProc.Dispose() ' try to stop it
eProc = Nothing
Process.GetProcessById(explorerID).Kill() ' try to kill it
Catch
End Try
End If
explorerID = 0 ' and reset proccess ID
End SubAnd to close it after usage or at least at exit.
As I can see:
HTML Code:
Process.GetProcessById(explorerID).Kill()
AppActivate(explorerID)
...don't work as expected or at all.