杀掉进程

huming1023 2007-10-08 03:06:13
小弟我根据句柄杀掉进程,t 有值可为什么返回的k总是0呢,望各位大哥解小弟心中之疑惑。
代码如下:
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

IntPtr t = new IntPtr(excel.Hwnd);
int k = 0;
GetWindowThreadProcessId(t,out k);
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
...全文
116 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjlove51 2007-10-11
  • 打赏
  • 举报
回复
。。
huming1023 2007-10-11
  • 打赏
  • 举报
回复
各位说的方法我都试过还是不行,是否这种取进程ID的方法只能在winform中取得到,而在web程序中不行呢?
lextm 2007-10-10
  • 打赏
  • 举报
回复
Process类里面有这方面的static方法,已经封装好了,没必要自己做。
Optione 2007-10-08
  • 打赏
  • 举报
回复

[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd,//窗口句柄
out uint lpdwProcessId //返回进程ID
);

GetWindowThreadProcessId用法是对的.检查一下excel.Hwnd的值.
Mittermeyer 2007-10-08
  • 打赏
  • 举报
回复
写得不对吧,试试看这样

[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();
Mittermeyer 2007-10-08
  • 打赏
  • 举报
回复
写得不对吧,试试看这样

[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();

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧