The following code snippet can be used to get the status of any process or an application given its name or PID (Process ID).
using System.Diagnostics;
private void GetProcessStatus()
{
try
{
//If you know the name of the process
Process[] myProcesses = Process.GetProcessesByName("mspaint");
//If you know the PID of the process use the commented line below
//Process[] myProcesses = Process.GetProcessById("2341");
//Check to see if the process array length is greater than 0
if(myProcesses.Length > 0)
{
MessageBox.Show("The Process Microsoft Paint(mspaint) is currently running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The Process Microsoft Paint(mspaint) is currently NOT running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch(Exception ex)
{
MessageBox.Show("An Exception Occoured: " + ex.Message, "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Posted by: Praveen | September 8, 2008





mmm… that doesn’t works correctly.
If the process are still alive works but if the process has been killed before the call at Process.GetProcessById(”2341″) an exception occurs.
By: Andrea Girardi on November 26, 2008
at 1:07 pm
Just use the Exception Handler.
By: Praveen on November 28, 2008
at 2:18 pm