March 11, 2021

How to programmatically get all processes from task manager using C#

  March 11, 2021

We may come across different scenarios where we need to get the list of all applications/processes running in the background of the Window OS.

Manually we can go to the task manager and check the processes tab to see the list.


But if we are trying to automate a scenario and if we want to do any action like Kill the process, close the process, Get the runtime of the process, Know used memory, etc we may need to take the list of running processes programatically.

For that, we can use the Processes method under System.Diagnostics Class

A sample code to get all running proccesses and print the name to the console is given below.
We can customize this to any format according to our requirements.

public void getAllRunningProcesses()
{
	Process[] processlist = Process.GetProcesses();
	foreach (Process theprocess in processlist)
	{
		Console.WriteLine(theprocess.ProcessName);
	}
}
logoblog

Thanks for reading How to programmatically get all processes from task manager using C#

Previous
« Prev Post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...