从Windows服务全局键盘钩子 [英] Global Keyboard Hook from windows service

查看:1196
本文介绍了从Windows服务全局键盘钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能写在Windows(XP和7)服务的全球键盘挂钩? (使用SetWindowsHookEx函数并没有一个系统的服务工作)

Is it possible to write a global Keyboard Hook from windows(xp and 7) service ? ( using SetWindowsHookEx didn't work from a system service )

推荐答案

的文档 SetWindowsHookEx函数说:

,或在同一桌面与调用线程的所有线程。

or with all threads in the same desktop as the calling thread.

因此​​,你需要用相同的桌面关联(即使不考虑终端服务,并且会有多个桌面:正常的桌面,安全桌面(用于UAC和登录)和屏幕保护程序)。

So you need to be associated with the same desktop (and there will be multiple desktops even without considering terminal services: the normal desktop, the secure desktop (used for UAC and login) and the screen saver).

由于服务不带有交互式会话相关的(和,从Windows V6,不能),你就需要在用户的会话中的过程中做了钩,并通过命名管道与后端服务(如通信。 )。而且不要忘了测试,没有一登录,并且多个用户登录。

Since services are not associated with an interactive session (and, from Windows V6, cannot be) you'll need a process within the user's session to do the hooking, and communicate with the backend service (eg. via a named pipe). And don't forget to test with no-one logged in, and multiple users logged in.

这篇关于从Windows服务全局键盘钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆