.netexcelcomprocessoffice-pia

How to stop an Excel process that I started from a C# .Net application?


I'm running Excel from a C# .Net application and having trouble getting the process to shut down. How can I get the Excel process to shut down correctly from my C# program?


Solution

  • Try this:

    foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
            {
                if (process.MainModule.ModuleName.ToUpper().Equals("EXCEL.EXE"))
                {
                    process.Kill();
                    break;
                }
            }