0

Hi. In C#, how do I check if, for example, calculator is running (calc.exe) in task manager process? and how do I end the calc.exe process? Thank you.

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Clawsy
1

Very simple. Just loop through the processes list and check the name of the current process:

//don't forget: using System.Diagnostics;
            try
            {
                Process[] p = Process.GetProcesses();//system processes in an array
                for (int i = 0; i < p.Length; i++)
                {
                    
                    if (p[i].ProcessName == "calc")//checkcurrent process name
                    {
                        //we got it
                        MessageBox.Show("Calculator process found - we will kill it after you press ok");
                        p[i].Kill();//this is the process
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

Their name does not contain the *.exe extension. Good luck :).
Clawsy.

Edited by Clawsy: n/a

0

If your problem is solved I'm glad for you and don't forget to mark the thread as solved.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.