写得不对吧,试试看这样  [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(); 

解决方案 »

  1.   

    写得不对吧,试试看这样  [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(); 
      

  2.   


    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    private static extern uint GetWindowThreadProcessId(IntPtr hWnd,//窗口句柄
    out uint lpdwProcessId //返回进程ID
    ); GetWindowThreadProcessId用法是对的.检查一下excel.Hwnd的值.
      

  3.   

    Process类里面有这方面的static方法,已经封装好了,没必要自己做。
      

  4.   

    各位说的方法我都试过还是不行,是否这种取进程ID的方法只能在winform中取得到,而在web程序中不行呢?