Code Tips

How to find all processes running on a machine

Here is sample code that shows all the processes running on a machine and how you would iterate through them to shut them down.


//--Declare an array of processes
Dim myProcesses() as System.Diagnostic.Process; 
//--A single process variable
Dim myProcess As System.Diagnostic.Process; 
//--Get the list of processes
myProcesses = System.Diagnostic.Process.GetProcesses();  
//--Iterate through the process array.
For Each myProcess in myProcesses 
  Console.WriteLine(myProcess.ProcessName);
  //-- If you want to stop a process 
  //-- with a graphical interface then call
  myProcess.CloseMainWindow();
  //-- If you want to stop a process without 
  //-- a graphical interface then call
  myProcess.Kill(); 
Next 
Comments Off on How to find all processes running on a machine