-2

I want to kill all the excel process which are running in the system before I start my application.How can I do that in C#?

Srinidhi
  • 45
  • 3

2 Answers2

4

This will work:

foreach (Process p in Process.GetProcessesByName("EXCEL"))
{
    p.Kill();
}
Archibald
  • 456
  • 1
  • 7
  • 20
Jamie
  • 611
  • 1
  • 5
  • 20
  • I took out the .EXE as the process name is supposed to be a "friendly name" as defined by the MSDN, a name without file extension. – Archibald Aug 18 '16 at 20:15
2
using System.Diagnostics;
try
{
      foreach (var p in Process.GetProcessesByName("EXCEL.EXE"))
          p.Kill();
}
Mike
  • 874
  • 1
  • 8
  • 15