Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET Get Process list and kill process

Tags:

process

vb.net

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
like image 299
BlackOpty Avatar asked Sep 19 '26 22:09

BlackOpty


2 Answers

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:

Process.Start("pname.exe")
like image 83
nnm Avatar answered Sep 22 '26 02:09

nnm


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

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()
like image 35
J.J. Zwaard Avatar answered Sep 22 '26 00:09

J.J. Zwaard