Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System wide keyboard hook on Vista and later

I have a system-wide keyboard hook DLL that I have created that has been working successfully for years in Windows XP.

However, it appears that in certain later versions of Windows (Vista Home Premium, and Windows 7, to name a couple), the hook either does not work at all, or it simply works only locally within the application that installed it.

I have seen it suggested in a couple of places on the internet to change the WH-KEYBOARD to WH-KEYBOARD-LL in the call to SetWindowsHookEx, but this doesn't appear to help when I tried it. Is there something else I need to change in addition to changing the hook type to WH-KEYBOARD-LL?

(P.S.: I had to define WH-KEYBOARD-LL as 13, since it not defined in Delphi. I'm assuming this is accurate.)

like image 468
kes Avatar asked Oct 01 '09 19:10

kes


1 Answers

Make sure the process hosting the hook is at the same privilege level of the application you intend to hook. Keyboard and other hooks are a high security risk, so Vista and later was changed to only allow system-wide hooks in processes within a common certain security context. In other words, if you start the hook host process with user rights, it will only hook processes that are at the same privilege level. If you think about it, this make sense because you would not want a user-level process being able to inject code into an admin-level process. That is bad on so many levels.

like image 179
Allen Bauer Avatar answered Oct 16 '22 05:10

Allen Bauer