I would like to be able to "press" the Scroll Lock key (from an application), so that the 开发者_如何学Pythonscroll lock led on the keyboard will turn on or off.
I've used the DllImport on the function keybd_event (from user32.dll) to do so, and my app runs as a service on win xp.
It's works fine, but when I lock the computer (win+L) that function stops working.
I've tried running the service as Local Service and as Admin but it made no difference.
any suggestions?
thanks.
One possibility would be to subscribe to the notification of the workstation being unlocked and then do the deed at that point.
first of all you need a global hook for this and since you are running from a windows service you will have to make the service interactive, this can be set from Service control panel on LogOn tab-> Allow service to interact with desktop.
Global hooks aren't easy with managed code though. You will still need some unmanaged code to call it but this might help you: http://www.codeproject.com/KB/system/globalsystemhook.aspx
I can't say for sure if this will work when you lock the computer, because windows takes extra precautions there to prevent keyloggers from stealing passwords.
For educational purposes though, if you wanted to intercept the login, the documented way would be to replace gina.dll.
thanks for the help guys.
what I end up doing, was replacing msgina.dll, with my own dll (ginastub.dll), and in it opened a new thread (that run in the winlogon session). my service can communicate with that thread using named pipe, and send it commands to "press" the key.
it took a while but it seem to work :)
精彩评论