Yakov
Yakov

Reputation: 318

Key Event Handling in Windows Services C#

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.

Upvotes: 1

Views: 1335

Answers (1)

Simon Chadwick
Simon Chadwick

Reputation: 1148

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!

Upvotes: 1

Related Questions