VB.NET 获取进程列表并杀死进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11100732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:09:18  来源:igfitidea点击:

VB.NET Get Process list and kill process

vb.netprocess

提问by BlackOpty

i want to insert all processes that running into listbox,
and also how to "kill" process and start process?

我想插入所有运行到列表框中的进程,
以及如何“杀死”进程并启动进程?

for i = 0 to procCount
...
next i

回答by nnm

the list + kill:

列表+杀死:

For Each p As Process In Process.GetProcesses
    ListBox1.Items.Add(p.ProcessName.ToString)
    If String.compare(p.ProcessName, "iexplore",true) = 0 Then
        p.Kill()
    End If
Next

use the kill()to kill process
to open process:

使用kill()to kill process
打开进程:

Process.Start("pname.exe")

回答by J.J. Zwaard

You can also create a list with all running processes of Excel before starting Excel programatically (using Linq statement):

您还可以在以编程方式启动 Excel 之前创建一个包含所有正在运行的 Excel 进程的列表(使用 Linq 语句):

Dim lstExcelProcess As List(Of Process) = (From p As Process In Process.GetProcesses Where p.ProcessName.ToUpper Like "Excel*".ToUpper).ToList

And after you finished what you had to do, kill the only process that was not listed before:

在你完成你必须做的事情后,杀死之前没有列出的唯一进程:

Dim process As Process = (From p As Process In process.GetProcesses Where p.ProcessName.ToUpper Like "Excel*".ToUpper And Not lstExcelProcess.Contains(p))(0)
            process.Kill()