title: Killing EXCEL.exe Process from C# in a Windows Service
body: <p>I have a windows service that opens up an Excel spreadsheet via  the Microsoft.Office.Interop.Excel.Application object.</p>
  
  <pre><code>Application xlApp = new Application();
  Workbook workbook = xlApp.Workbooks.Open(fileName, 2, false);
  ...
  ...
  workbook.Close();
  xlApp.Quit();
  </code></pre>
  
  <p>I would like to kill the EXCEL.exe process that is left running after it is done working with the workbook.</p>
  
  <p>I've tried the following with no success...</p>
  
  <pre><code>// This returns a processId of 0
  IntPtr processId;
  GetWindowThreadProcessId(new IntPtr(xlApp.Hwnd), out processId);
  Process p = Process.GetProcessById(processId.ToInt32());   
  p.Kill();
  </code></pre>
  
  <p>Anyone have any ideas as to how I can do this via a Windows Service?</p>