tags:

views:

73

answers:

4

I've started a process through system.diagnostics .process.start("C:/process.exe") Now my question is, how can I terminate the same process in vb.net

+1  A: 

The Start() method returns a Project object. Call its Kill method:

  Private WithEvents MyProcess As Process

  Private Sub MyProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyProcess.Exited
    MyProcess = Nothing
  End Sub

  Private Sub RunIt()
    MyProcess = Process.Start("notepad.exe")
  End Sub

  Private Sub StopIt()
    If MyProcess IsNot Nothing Then MyProcess.Kill()
  End Sub
Hans Passant
+2  A: 
dim myProc as Process
myProc=Process.Start("C:\Process.exe")

...
myProc.kill
Doogie
A: 

Others have mentioned the Kill method to force a process to terminate. You might wish to call CloseMainWindow so that the app can have a chance to shut down gracefully.

Chris Dunaway