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

Fixing javascript error: Cannot read properties of null (reading 'querySelector') issue when using CSS identifier in selenium

 JavaScript is another way to interact with web elements when normal selenium methods fail to act. But one issue with javascript is, it does...