日期:2014-05-17 浏览次数:21056 次
添加引用: using System.Runtime.InteropServices; 结束进程代码 [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int id); public void KillExcellProcess(string path) { Excel.ApplicationClass excel = new Excel.ApplicationClass();//.applicationclass(); excel.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); IntPtr t = new IntPtr(excel.Hwnd); int k = 0; GetWindowThreadProcessId(t, out k); System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k); p.Kill(); }
------解决方案--------------------
学习...还没用过这个东东。