c# - 低级鼠标 Hook 不会在管理进程上触发 mousedown/mouseup 事件

标签 c# windows-8.1 windows-10 mouse-hook

我现在正在编辑此项目,因为我认为我已经查明了问题,这似乎是 Win8.1 和 Win10 的操作系统错误。问题摘要仍然与之前相同“低级鼠标 Hook 不会在管理进程上触发 mousedown/mouseup 事件”...对于管理应用程序,如果非管理员启动自己的低级 Hook 。

重现问题的步骤:

  1. 下载演示应用 here
  2. 以管理员身份运行应用
  3. 确保监控鼠标向上/向下/单击事件
  4. 确认第 2 步启动的应用能够监控管理进程(包括其自己的窗口)上的鼠标向上/向下/单击事件
  5. 以非管理员身份运行应用的另一个实例
  6. 确保监控鼠标向上/向下/单击事件

结果:请注意,以管理员身份运行的应用程序实例(从 #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+。

告诉我更多

关于c# - 低级鼠标 Hook 不会在管理进程上触发 mousedown/mouseup 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171743/

相关文章:

c# - 检测 Windows 8.1 商店应用程序中的屏幕缩放比例

google-chrome - 如何调试自签名证书?

windows-store-apps - 使用 VS 2015 运行在 Windows 10 上构建的 Windows 8.1 应用程序

c# - 在方法中使用 const

c# - 如何判断一个窗口是模态窗口还是 MDI 窗口?

c# - 动态删除代码删除整个表

windows-8.1 - 出现错误: The smart card requires drivers that are not present on this system

c# - NHibernate - 带有 WHERE 子句的唯一索引

c# - XAML Hub Control Windows 8.1 Universal,InvokeCommandAction 未触发

c# - WPF 经典 Windows 应用程序作为 Windows 10 专业版上的自定义 Shell 时出现屏幕键盘问题