开发者

Key Event Handling in Windows Services C#

开发者 https://www.devze.com 2022-12-31 03:51 出处:网络
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.

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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消