VB.NET获取进程列表并终止进程

时间:2012-06-19 12:17:27

标签: vb.net process

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

for i = 0 to procCount
...
next i

2 个答案:

答案 0 :(得分:8)

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

使用kill()来杀死进程
打开过程:

Process.Start("pname.exe")

答案 1 :(得分:1)

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

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

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

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()