简体   繁体   English

用VB.NET杀死窗口中正在运行的进程

[英]Killing of running process in window with VB.NET

如何使用VB.NET 2.0框架杀死Windows中其他正在运行的进程?

杀死所有记事本实例:

Process.GetProcessesByname("Notepad").ForEach(Sub(x) x.Kill())

You and simply kill the process by kill() method. 您只需通过kill()方法杀死该进程。

    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. 您可以使用System.Diagnostics.Process.Kill完成此操作。 You can find the answer as well on How do I kill a process using Vb.NET or C#? 您也可以在如何使用Vb.NET或C#杀死进程中找到答案 (both C# as VB.NET answers). (C#都作为VB.NET的答案)。

Look at the MSDN Page: Process.Kill() for some more details. 请查看MSDN页面:Process.Kill()了解更多详细信息。

Here is a code sample how to use it (took it parts from MSDN): 这是一个代码示例如何使用它(从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 . 您可以使用Process.GetProcessesByName Method 获取进程名称,并使用Process.GetProcessesByName Method Process.Kill Method

Example: 例:

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

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

MSDN Entries: MSDN条目:

MSDN - Process.Kill Method MSDN-Process.Kill方法

MSDN - Process.GetProcessesByName Method MSDN-Process.GetProcessesByName方法

Similar SO question: 类似的问题:

How do I kill a process using Vb.NET or C#? 如何使用Vb.NET或C#终止进程?

Hope this helps. 希望这可以帮助。

1st create a a.bat file and store it into bin or in your project folder 1创建一个a.bat文件并将其存储到bin或项目文件夹中
In batch file write following line 在批处理文件中,写以下行

tskill (your process name)

save it as .bat 将其另存为.bat

in coding write following line 在编码中写以下行

System.Diagnostics.Process.Start("Your bat file path")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM