How To List the Name of All Running Processes in C#

Friends,

In this article we will see how to print a list of all the running processes on a machine using C#. To list all the processes, we will use one of the namespaces provided by Microsoft known as System.Diagnostics. As in MSDN, this namespace provides classes that allow you to interact with system processes, event logs and performance counters.

This namespace contains a class named Process that we will use to iterate through the process list. So, let's write some code.

  1. private void ListProcesses()  
  2. {  
  3.     Process[] processCollection = Process.GetProcesses();  
  4.     foreach (Process p in processCollection)  
  5.     {  
  6.         Console.WriteLine(p.ProcessName);  
  7.     }  

In the code snippet above, we're getting the list of all the processes using the static GetProcesses() function defined in the Process class. After the list is retrieved, we iterate through each process and print the process name.

A sample output on my Windows 8.1 machine is as below:


I hope you like this article! Keep learning and sharing! Cheers!

Up Next
    Ebook Download
    View all
    Learn
    View all
    Think. Innovate. Grow.