[DllImport("User32.dll",CharSet= CharSet.Auto)]

public static extern int GetWindowThreadProcessId(IntPtr hwnd,out int ID);

//传入一个应用程序excel对象

public static void Kill(Excel.Application excel)

{

  IntPtr t=new IntPtr(excel.Hwnd);

  int k=0;

  GetWindowThreadProcessId(t,out k);

  System.Diagnostics.Process p= System.Diagnostics.Process.GetWindowThreadProcessById(k);

  p.Kill();

}

posted on 2013-05-16 17:29  逐梦☆飞扬  阅读(382)  评论(0)    收藏  举报