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

How to send email from current Outlook instance using Java + VBScript

If we are using .Net, we can easily access outlook and send emails using its own libraries. But what if we are using Java? Here we can seek ...