0

From vb.net, I need to terminate a process that often hangs. I normally use process.kill, which works on most processes, but not on a hung process. If I use taskkill /im process.exe it does not terminate either. But if I use taskkill /im process.exe /f, it terminates fine. So the questions is, what is the vb.net equivalent for taskkill /f?

Thank You.

rerat
  • 321
  • 3
  • 14
  • possible duplicate of [How do I kill a process using Vb.NET or C#?](http://stackoverflow.com/questions/116090/how-do-i-kill-a-process-using-vb-net-or-c) – Victor Zakharov Apr 09 '14 at 23:59

2 Answers2

1

You will need to create a ProcessStartInfo with your arguments and the file name, in this case "taskkill" then you can start the process and it will run the taskkill command. This is a Subroutine that you can call that will do it. you will need to put Imports System.Diagnostics at the top of your Class file.

Imports System.Diagnostics
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        KillHungProcess("Notepad.exe") 'Put your process name here
    End Sub
    Public Sub KillHungProcess(processName As String)
        Dim psi As ProcessStartInfo = New ProcessStartInfo
        psi.Arguments = "/im " & processName & " /f"
        psi.FileName = "taskkill"
        Dim p As Process = New Process()
        p.StartInfo = psi
        p.Start()
    End Sub
End Class
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • I thought of that, but since XP Home does not have taskkill, I would rather use .net or API to get it done. We still have a lot of clients using XP, so would like to use taskkill as a last resort. Any idea how to accomplish this using API or .net? – rerat Apr 10 '14 at 04:01
  • See if this SO questions accepted answer helps http://stackoverflow.com/a/7956651/479512 – Mark Hall Apr 10 '14 at 04:07
  • I was figuring there would be an easy way using vb.net, but since there is not I will just use taskkill via process.start and not worry about XP Home. – rerat Apr 15 '14 at 23:13
0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Shell("taskkill /F /IM process-name-here.exe /T", 0)

End Sub
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Cyclo
  • 1