views:

141

answers:

1

Hi!

I want to create a windows service that may log pressed keys into files.

For handling global key events I use hooks, hooks works great for desktop apps. But it doesn't work for the services.

Is it possible to develop a windows service with key event handling? Developing on C#...

Thanks for your time.

A: 

Two things to check:

  1. In your call to SetWindowshookEx() ensure that the dwThreadId parameter is 0, so that "the hook procedure is associated with all existing threads running in the same desktop as the calling thread", according to MSDN.
  2. The service must be granted access to the desktop. Do this from the Service properties, "Log On" tab, Log on as Local System account, and check "Allow service to interact with desktop".

Good luck!

Simon Chadwick