2

When I attempt to use SetCursorPos at the Windows Vista/7 login screen, true is returned which at first made me think it was working. However, when I call GetCursorPos it gives me:

-858993460,-858993460

Any thoughts why? Is this a "security feature" or am I using it incorrectly? The code works fine on non-login (i.e. normal) desktop.

Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
  • 1
    `-858993460` is `0xFFFFFFFF` in hex which would indicate an error condition or unset variable. – ChrisF Dec 26 '09 at 19:37
  • 3
    @ChrisF -- no way, -858993460 is 0xCCCCCCCC. Which, indeed, indicates an unset variable in MSVC debug builds. – atzz Dec 26 '09 at 20:28
  • @atzz - oops - I used the Windows calculator and got `0xFFFFFFFFCCCCCCCC` and picked the wrong half! – ChrisF Dec 27 '09 at 15:14

3 Answers3

4

From the MSDN:

The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.

This page (where I got the above quote from) which asks the question "GetCursorPos not working if desktop is locked", has the following information:

You can't get this information while the desktop is locked. While the desktop is locked, the security subsystem takes over, and your desktop is off limits.

At that point, you would have to hook into the O/S (people have done it by replacing GINA.dll, but you can't do this in managed code, and on top of that, you can't do it in Vista, as it has a different model).

While the desktop is locked, you are going to have to do without cursor information if you are using managed code.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Did you understand that I need to get/set the current cursor position at the login screen, as opposed to my non-login desktop? – Nick Bolton Dec 26 '09 at 19:42
  • @Nick Bolton - yes, but I was trying to find information as to why you weren't able to. If it's not relevant then I apologise and I'll delete the answer. – ChrisF Dec 26 '09 at 19:44
  • Sorry no need to delete. What I'm trying to ascertain is whether I can get/set cursor position on the login screen; if you're saying no and this is the case then your answer is valid. – Nick Bolton Dec 26 '09 at 19:47
  • @Nick - from the (admittedly limited) research I've done it would appear you can't. – ChrisF Dec 26 '09 at 19:50
  • You can't. The login screen is a priveledged desktop. You would need to be running on that desktop to get the mouse position on it. – John Knoeller Dec 26 '09 at 20:35
  • The process *is* running on that desktop session. – Nick Bolton Dec 26 '09 at 20:45
  • @John Allow me to elaborate, the process is re-launched by a service when the switch from user desktop session is detected. The process is launched in the correct session, and we're in fact able to do limited interaction with this desktop (hook mouse/keyboard events). – Nick Bolton Dec 26 '09 at 20:47
4

On the login screen and on the security window you cannot send mouse or keyboard events. This is a security measure for Windows in order to prevent unauthorized access from different programs.

sorin
  • 161,544
  • 178
  • 535
  • 806
1

Alternative solution: It is possible (but very tricky) to use mouse_event (which does work at login screen) instead of SetCursorPos. I don't have time to post code now, but if asked I may update this answer...

Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
  • Can you please post more info? I need to send mouse/keyboard input to the lock and login screens and can't figure it out. Thanks! – tunafish24 Jun 24 '15 at 05:24