Kill Process from task manager
I did a project in vb.net, 3.5 framework using Visual Studio 2008.My Question is regarding killing the process from task manager. Whenever I am exiting my application by the Close button ('X') or an Exit button (P.S here 'Exit' is a button in the windows application) the process exists in the task manager and I had to remove it manually. I don't want to do that. The name of the process is iMaxAutotech.exe. I have used this code under form_closing event and in the exit button but it's not working ..grrh!!!
Under Exit Button :
Private Sub Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mresult As MsgBoxResult
mresult = MsgBox("Are you sure you want to exit?", MsgBoxStyle.YesNo)
If mresult = MsgBoxResult.Yes Then
Me.Close()
End If
Dim plist As Process() = Process.GetProcesses()
For Each p As Process In plist
Try
If p.MainModule.ModuleName.ToUpper() = "iMaxAutotech.exe" Then p.Kill()
Catch
'seems listing modules for some processes fails, so better ignore any exceptions here
End Try
Next p
End Sub
and in the Form Closing Event :
Private Sub Form3_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim plist As Process() = Process.GetProcesses()
For Each p As Process In plist
Try
If p.MainModule.ModuleName.ToUpper() = "iMaxAutotech.exe" Then p.Kill()
Catch
'seems listing modules for some processes fails, so better ignore any exceptions here
End Try
Next p
End Sub
I want the vb.net code for that,can any1 help me plz plz.It's very urgent ...Thanks in advance