Saturday, 23 May 2015

How to kill process by name in C#.Net

When working with Selenium or any other automation tool, we face the situation wherein we need to kill all the processes of specific name say iexplore or chrome or any application process.

We can use below code in c#.Net to kill the process by name.

Please note that Process class is available in System.Diagnostics namespace. So you will need to use that namespace in the program.

using System.Diagnostics;

 public void KillProcess()
        {

            try
            {
                foreach (Process process in Process.GetProcessesByName("IExplore"))
                { 
                    //kill the process 
                    process.Kill();
                }
            }
            catch (Exception ex)
            {
                //show the exceptions if any here
                Console.WriteLine(ex.ToString());
            };

        }

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books