rerat rerat - 1 year ago 120 Question

Need help forcefully terminating a process in

From, 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 equivalent for taskkill /f?

Thank You.

Answer Source

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
    End Sub
End Class
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download