Keystroke log in a service
-
Hi all, is it possible to intercept keystrokes in a service? Every Service run in a different desktop from the one a user logs, so basically I think this service should grab any keystrokes in any desktop. Do you have any experience on that? Thanx alot n' Merry Xmas. :-D
-
Hi all, is it possible to intercept keystrokes in a service? Every Service run in a different desktop from the one a user logs, so basically I think this service should grab any keystrokes in any desktop. Do you have any experience on that? Thanx alot n' Merry Xmas. :-D
> ..so basically I think this service should grab any keystrokes in any desktop Not at all. :) To grab keystrokes you have to call the
SetWindowsHookEx
API. Problem:SetWindowsHookEx
resides in user32.dll and user32 functions are generally bound to a specific desktop. Because most services don't run under the logged-on user account you won't be able to grab the keystrokes of the loged-on user either (nor the keystrokes of any other desktop, like WinLogon for example) - at least not directly. Fortunately there are two exceptions to the above rule: 1. Services running under the local System account can be made interactive. In other words, they can interact with the user and thus grab its keystrokes too. But this way you will only grab the keystrokes of the loged-on users desktop -> it's the same as if you would make an ordinary win32 exe right away. 2. You can "connect" a (service) thread to a desktop viaSetThreadDesktop
. Knowing this, you could try on of the following: a) Spawn a new thread for each desktop that is present on the system; then callSetThreadDesktop
andSetWindowsHookEx
from within each thread. b) Since there is only one interactive desktop (=desktop, that receives the user input) at any time, simply callSetThreadDesktop
andSetWindowsHookEx
always when the active desktop gets switched. Note: This were just presumptions from the top of my head -> for the exact behavior/terminology and implementation check the MSDN documentation. RK -
> ..so basically I think this service should grab any keystrokes in any desktop Not at all. :) To grab keystrokes you have to call the
SetWindowsHookEx
API. Problem:SetWindowsHookEx
resides in user32.dll and user32 functions are generally bound to a specific desktop. Because most services don't run under the logged-on user account you won't be able to grab the keystrokes of the loged-on user either (nor the keystrokes of any other desktop, like WinLogon for example) - at least not directly. Fortunately there are two exceptions to the above rule: 1. Services running under the local System account can be made interactive. In other words, they can interact with the user and thus grab its keystrokes too. But this way you will only grab the keystrokes of the loged-on users desktop -> it's the same as if you would make an ordinary win32 exe right away. 2. You can "connect" a (service) thread to a desktop viaSetThreadDesktop
. Knowing this, you could try on of the following: a) Spawn a new thread for each desktop that is present on the system; then callSetThreadDesktop
andSetWindowsHookEx
from within each thread. b) Since there is only one interactive desktop (=desktop, that receives the user input) at any time, simply callSetThreadDesktop
andSetWindowsHookEx
always when the active desktop gets switched. Note: This were just presumptions from the top of my head -> for the exact behavior/terminology and implementation check the MSDN documentation. RKThanx a lot. I will check for something. Merry xmas