I'm wanting to create a sort of task manager type application where the software displays the running processes, associated program and the amount of time the program has been running for.
I ahve managed to get code working that will retrieve the names of all process being run, however I am not sure how to retrieve the time for the process.
The code I'm using for retrieving the process list it:
' Start with an empty ListBox.
lstProcessList.Items.Clear()
' Display ProcessName property in the list area.
lstProcessList.DisplayMember = "ProcessName"
' Load info on all running processes in the ListBox control.
Dim p As Process
For Each p In Process.GetProcesses
lstProcessList.Items.Add(p)
Next
I'm assuming I need to change ProcessName to something else, but does anyone know what it should be

Creating a task manager application
ToePwar
Well I actually meant it as example on working with Process class. Here is more complete code:
Dim p As ProcessDim processDescription As String
Dim elapsed As TimeSpan
For Each p In Process.GetProcesseselapsed = DateTime.Now - p.StartTime
'Just skip process that we are not allowed to query
On Error Resume Next
processDescription = p.ProcessName
processDescription = processDescription & " " & elapsed.ToString()
ListBox1.Items.Add(processDescription)
Next
Max
DLiu
Thanks for that,
Is it possible to specify the process name (ie, I want to find out how long Notepad has been running).
Mark Seddon
Hi,
What time do you want to know, if it is time for how long the process is runing here it is:
Dim elapsed As TimeSpanelapsed = DateTime.Now - Process.GetCurrentProcess().StartTime
MessageBox.Show(elapsed.ToString())
Max
AgedBOY
Thanks to both of you, I've learned a lot from just reading the code.
Thanks again, I can now get started.
Joe Lathrop
I'm afraid this is incorrect.
This will get information on the task manager itself but no other process.
Dim Proc As Process() = Process.GetProcesses For i As Short = 0 To Proc.Length - 1 If Proc(i).Id > 4 Then ' Don't process the idle timer and system process Dim elapsed As TimeSpan = Date.Now - Proc(i).StartTimeTextBox1.Text &= elapsed.ToString & vbCrLf
End If Nextcaddy36
Dim Proc As Process() = Process.GetProcessesByName("Notepad")