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

Introduction

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.

private void ListProcesses()
{
    Process[] processCollection = Process.GetProcesses();
    foreach (Process p in processCollection)
    {
        Console.WriteLine(p.ProcessName);
    }
}

 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!


Similar Articles
Rebin Infotech
Think. Innovate. Grow.