如何使用VB.NET 2.0框架杀死Windows中其他正在运行的进程?
杀死所有记事本实例:
Process.GetProcessesByname("Notepad").ForEach(Sub(x) x.Kill())
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
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())
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.GetProcessesByName Method
Similar SO question:
How do I kill a process using Vb.NET or C#?
Hope this helps.
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.