3

I would like to be able to "press" the Scroll Lock key (from an application), so that the scroll 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.

lev
  • 3,986
  • 4
  • 33
  • 46
  • I've never used that key in my life (except to turn it off when it randomly turns on)... but interesting question nonetheless, +1. – user541686 Jan 12 '11 at 20:02
  • 1
    Yes, a session switch does this. If it makes any difference: your program won't work at all on Vista or Win7. No workaround. – Hans Passant Jan 12 '11 at 20:05
  • @Hans: How can you possibly be so sure that there’s “no workaround”? I bet a device driver can probably do it. While not always a practicable workaround, it is certainly one. – Timwi Jan 12 '11 at 20:08
  • 1
    Hmya, the not always practical workaround for a worn-out laptop battery is a diesel generator. – Hans Passant Jan 12 '11 at 20:17
  • Maybe you could try launching your program on the winlogon desktop; no idea if this will actually work, but it sounds somewhat plausible :) – Luke Jan 12 '11 at 22:29

3 Answers3

0

One possibility would be to subscribe to the notification of the workstation being unlocked and then do the deed at that point.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

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.

Tudor Carean
  • 972
  • 2
  • 12
  • 22
0

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 :)

lev
  • 3,986
  • 4
  • 33
  • 46