displaying running processes in listbox

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I've been trying to make a process manager that will show more detail than Task Manager, but I'm stuck at one point. I would like the listbox to show realtime data for what processes are running, so I tried to set the data source to the processes. It doesn't list the processes when I do that. Is there a better way than to load all of the processes and check on a timer if they are still running?
 
Put the code found here: (http://www.devx.com/vb2themax/Tip/18728) (Extracted below) in a timers Tick event and you should be set:

VB.NET:
[COLOR=#008000]' This code assume that you've used the following Imports[/COLOR]
[COLOR=green]' Imports System.Diagnostics.[/COLOR]

[COLOR=green]' Start with an empty ListBox.[/COLOR]
lstProcesses.Items.Clear()
[COLOR=green]' Display ProcessName property in the list area.[/COLOR]
lstProcesses.DisplayMember = "ProcessName"

[COLOR=green]' Load info on all running processes in the ListBox control.[/COLOR]
Dim p As Process
For Each p In Process.GetProcesses
    lstProcesses.Items.Add(p)
Next
 
I got it working with this.
VB.NET:
[SIZE=2][COLOR=#0000ff]Option[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Explicit[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]On
Imports[/COLOR][/SIZE][SIZE=2] System.Diagnostics
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] p [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Process
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
ListBox1.Items.Clear()
ListBox1.DisplayMember = [/SIZE][SIZE=2][COLOR=#800000]"ProcessName"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] p [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] Process.GetProcesses
ListBox1.Items.Add(p)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
How can I get it so that when I select a process in listbox1, it will show some other things in text boxes, like PeakVirtualMemorySize?
 
Add and remove processes from listbox on timer

I have my program mostly working to show information about the processes that are currently running, but I'm trying to get it to keep the list updated on a timer, by adding processes that have started and removing ones that have stopped. I'm not sure what to put in the loop to make this happen. My form load event looks like this.
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RadioButton6.Checked = True
        ListBox1.Items.Clear()
        ListBox1.DisplayMember = "ProcessName"
        For Each pt In Process.GetProcesses
            ListBox1.Items.Add(pt.ProcessName)
        Next
        Label4.Text = "Processes: " & ListBox1.Items.Count
        If My.Settings.timerinterval <> "" Then
            Timer1.Enabled = True
            Timer1.Interval = My.Settings.timerinterval * 1000
            Timer1.Start()
        End If
        If My.Settings.tooltipinterval <> "" Then
            TextBox5.Text = My.Settings.tooltipinterval
        End If
    End Sub

This is currently adding the process name to the listbox, but I originally had it adding "pt", not "pt.ProcessName". If I change it to process name, some of the other parts break, because it can't give me the details about a process from a string. I'd appreciate any help. Thanks.
 
Back
Top