Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Keyboard Hook from windows service

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

like image 671
jacob Avatar asked Apr 28 '11 07:04

jacob


1 Answers

The documentation for SetWindowsHookEx says:

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

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

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.

like image 78
Richard Avatar answered Oct 03 '22 19:10

Richard