Enumerating Processes & much more! Update - Real Time Updating
Looking over the Code Bank, I wasn't really able to find much on enumerating processes except for a WMI example. Since it seems like a lot of people are asking for such a thing, I decided to post an example I made up.
The example I've added is like a mini task manager. Below, I'll show you have to enumerate a list of processes and then add them to a ListView. My example also shows you how to obtain a bunch of different information about the processes and how to close them out as well.
There's a lot more features I'm going to add soon, so any suggestions, fixes, or code improvements are very much welcomed.
Now, on to enumerating processes...
There are a ton of different ways to go about this, so I'm just going to use the method I'm most familiar with.
First, I declare an array of processes and assign that array all of the running processes:
VB.NET Code:
Dim Processes() As Process = System.Diagnostics.Process.GetProcesses
Here I fully qualified the path with System.Diagnostics, but that isn't necessary if you've imported the namespace.
Next, I'll loop through that list and retrieve the appropriate information. Since I'm adding the info to a ListView, I declare a variable to hold the ListViewItem and then I add the variable to the ListView at the end.
VB.NET Code:
For Each proc As Process In Processes
Dim lvi As New ListViewItem
lvi.Text = proc.ProcessName
lvi.SubItems.Add(proc.Id.ToString)
ListView1.Items.Add(lvi)
Next proc
And that's it! It's a super easy "process"
You can download my Process Manager to get a better look at the code in action and see all of the information I've retrieved using the Process Class.
I really hate code commenting and since I made this pretty quick, I didn't do much of that. So, if there are any questions, ask away
My project obtains a ton of information about the processes such as: Name, PID, Memory Usage, Description, Modules, and much more!.
If you just want to use it, all you have to do is build the project and run the created executable. You can use the code in any way you like. All I ask is that you don't re-package it and call it your own
Process Manager:
Latest Update: Version 1.7
-Fixed an issue where you had to "re-click" the selected item in order to see a change in process priority
-Added an icon
-Added the ability to suspend and resume processes