写得不对吧,试试看这样 [DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, IntPtr ID); IntPtr t = new IntPtr(excel.Hwnd);
int k = GetWindowThreadProcessId(t,IntPtr.Zero); ;
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
public static extern int GetWindowThreadProcessId(IntPtr hwnd, IntPtr ID); IntPtr t = new IntPtr(excel.Hwnd);
int k = GetWindowThreadProcessId(t,IntPtr.Zero); ;
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
public static extern int GetWindowThreadProcessId(IntPtr hwnd, IntPtr ID); IntPtr t = new IntPtr(excel.Hwnd);
int k = GetWindowThreadProcessId(t,IntPtr.Zero); ;
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd,//窗口句柄
out uint lpdwProcessId //返回进程ID
); GetWindowThreadProcessId用法是对的.检查一下excel.Hwnd的值.