Clean Logic

Clean Logic

How to kill a process in VB.net

The following sub is a barebones example of how to kill a process using visual basic.net. It scans through each running process on the host computer, searching for one which matches strProcesstoKill. If it finds it, it stops it and gives you a message. If it does not find it, it lets you know that no such process was found. You shouldn’t need any additional Imports to use process.getprocess(). Enjoy.


Private Sub Kill_Service()

  • Dim proc() As Process = Process.GetProcesses
  • Dim strProcesstoKill As String = “SERVICENAME”
  • Dim killed As Boolean = False
  • For i As Integer = 0 To proc.GetUpperBound(0)
    • If proc(i).ProcessName = strProcesstoKill Then
      • proc(i).Kill()
      • MsgBox(”Process has been halted.”)
      • killed = True
    • End If
  • Next
  • If killed = False Then
    • MsgBox(”Process not found.”)
  • End If

End Sub

Tags: , , , , , , ,

Leave a Reply