Close Excel process in C#

  [DllImport("User32.dll", CharSet = CharSet.Auto)]
  public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

  public static void shutExcel(Excel.Application app )

{      

             IntPtr t = new IntPtr(app.Hwnd);
             int k = 0;
             GetWindowThreadProcessId(t, out k);
             System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
             p.Kill();

}

posted on 2010-05-24 17:33  刘宁Toby  阅读(272)  评论(0编辑  收藏  举报