3

How we can kill the other running process in window with VB.NET 2.0 framework?

emerald
  • 329
  • 4
  • 5
  • 10

5 Answers5

3

You and simply kill the process by kill() method.

    Dim processList() As Process
    processList = Process.GetProcessesByName(ListBox1.Items(ListBox1.SelectedIndex).ToString)

    For Each proc As Process In processList
        If MsgBox("Terminate " & proc.ProcessName & "?", MsgBoxStyle.YesNo, "Terminate?") = MsgBoxResult.Yes Then
            Try
                proc.Kill()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    Next
AKZap
  • 1,181
  • 6
  • 17
  • 31
2

Kill all instances of notepad:

Process.GetProcessesByname("Notepad").ForEach(Sub(x) x.Kill())
talha2k
  • 24,937
  • 4
  • 62
  • 81
Basic
  • 26,321
  • 24
  • 115
  • 201
1

You can use System.Diagnostics.Process.Kill to accomplish this. You can find the answer as well on How do I kill a process using Vb.NET or C#? (both C# as VB.NET answers).

Look at the MSDN Page: Process.Kill() for some more details.

Here is a code sample how to use it (took it parts from MSDN):

' First find the process(es) you want to kill, for example searching for the name
Dim notepadProcesses As Process() = Process.GetProcessesByName("notepad")

' Loop over the array to kill all the processes (using the Kill method)
Array.ForEach(notepadProcesses, Sub(p As Process) p.Kill())
Community
  • 1
  • 1
Styxxy
  • 7,462
  • 3
  • 40
  • 45
1

You can get process name using Process.GetProcessesByName Method and kill it using Process.Kill Method.

Example:

Process[] processes = Process.GetProcessesByName("mspaint");

foreach (Process process in processes){
 process.Kill();
}

MSDN Entries:

MSDN - Process.Kill Method

MSDN - Process.GetProcessesByName Method

Similar SO question:

How do I kill a process using Vb.NET or C#?

Hope this helps.

Community
  • 1
  • 1
talha2k
  • 24,937
  • 4
  • 62
  • 81
-1

1st create a a.bat file and store it into bin or in your project folder
In batch file write following line

tskill (your process name)

save it as .bat

in coding write following line

System.Diagnostics.Process.Start("Your bat file path")
Tanmay Nehete
  • 2,138
  • 4
  • 31
  • 42