我现在正在编辑此项目,因为我认为我已经查明了问题,这似乎是 Win8.1 和 Win10 的操作系统错误。问题摘要仍然与之前相同“低级鼠标 Hook 不会在管理进程上触发 mousedown/mouseup 事件”...对于管理应用程序,如果非管理员启动自己的低级 Hook 。
重现问题的步骤:
- 下载演示应用 here
- 以管理员身份运行应用
- 确保监控鼠标向上/向下/单击事件
- 确认第 2 步启动的应用能够监控管理进程(包括其自己的窗口)上的鼠标向上/向下/单击事件
- 以非管理员身份运行应用的另一个实例
- 确保监控鼠标向上/向下/单击事件
结果:请注意,以管理员身份运行的应用程序实例(从 #2 开始)现在无法获取鼠标向上/向下/单击事件,但它仍然可以获取其他鼠标事件和所有键盘事件
有人遇到过这个问题吗?
最佳答案
操作:
...and it confirmed that mouseup/mousedown events are not getting triggered when foreground window is running as admin.
操作:
if my app is not running as admin then I cannot get all mouse/keyboard events,
从 Vista 开始,应用程序无法向提升的应用程序发布消息或在其上安装 Hook 。这是通过用户界面权限隔离 (UIPI) 和完整性来实现的(见下文)。
MSDN:
UIPI does not interfere with or change the behavior of window messaging between applications at the same privilege (or integrity) level. UIPI prevents lower-privilege processes from accessing higher-privilege processes by blocking the following behavior. A lower-privilege process cannot:
- Perform a window handle validation of a process running with higher rights.
- Use SendMessage or PostMessage to application windows running with higher rights. These APIs return success but silently drop the window message.
- Use thread hooks to attach to a process running with higher rights.
- Use journal hooks to monitor a process running with higher rights.
- Perform dynamic link library (DLL) injection to a process running with higher rights. Tell me more...
我记得在 Vista 发布之前,有一个可爱的 Word 文档,内容是关于为 Windows Vista 准备应用程序的,但遗憾的是我找不到它。
but if my app is running as admin then it cannot get mousedown/mouseup events
也许你的鼠标 Hook 有问题?如果没有看到您的代码,就无法判断。
Is this a known issue for Windows
据我了解,不适用于 Windows Vista+。
告诉我更多
- MSDN,“Windows 完整性机制设计”,https://msdn.microsoft.com/en-us/library/bb625963.aspx
关于c# - 低级鼠标 Hook 不会在管理进程上触发 mousedown/mouseup 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171743/