Sunday, August 11, 2013

How to kill a specific running application / process in C#

Sometime you may need to check some processes before launching some other applications. As an example, I want to kill all the other excel applications which are running on the PC before launching a new Excel file by the system.

Don't worry about the illustrated example. This was i have gone through while developing some desktop application. I thought this code snippet may help someone to make their job easy. So just published it.

In my previous C# example i have demonstrate creating message box buttons in windows application and execute some different code snippets based on button selection. Refer that article here.

  Process[] pname = Process.GetProcessesByName("excel");
  foreach (var item in pname)
  {
    item.Kill();
  }

In above example, I'm killing other running EXCEL applications / processes.

No comments:

Post a Comment