views:

758

answers:

1

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.)

+7  A: 

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.

Allen Bauer