111,093
社区成员




public bool get_Responding()
{
if (!this.haveResponding)
{
IntPtr mainWindowHandle = this.MainWindowHandle;
if (mainWindowHandle == IntPtr.Zero)
{
this.responding = true;
}
else
{
IntPtr ptr2;
this.responding = NativeMethods.SendMessageTimeout(new HandleRef(this, mainWindowHandle), 0, IntPtr.Zero, IntPtr.Zero, 2, 0x1388, out ptr2) != IntPtr.Zero;
}
}
return this.responding;
}
你的服务和那个程序不是运行在同一个会话中,而Process.Responding是通过向目标程序发送一个Windows测试消息,5秒内有响应则返回true,但前提是,要能正确取得目标进程主窗口句柄
有一个很简单的办法,挂一个全局钩子,任务桌面应用(有窗口的)启动你都会收到通知,有了这个就好办了,目标程序加载你的钩子模块,只需要双方作一次简单的通讯,比如全名管道,socket,全局事件(这里指内核事件,不是Net中的普通事件),共享内存