Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if desktop is locked [duplicate]

Tags:

desktop

winapi

Possible Duplicate:
How can I programmatically determine if my workstation is locked?

What is the best way to determine if the desktop is locked for the currently logged in user? I looked in MSDN and couldn't find any API calls to detect this. Did I miss something, or is there no simple call I can use?

like image 760
Jon Tackabury Avatar asked Apr 20 '09 13:04

Jon Tackabury


People also ask

Do programs still run when computer is locked?

Locking the computer means your apps are still ON and running. Logging/signing off will CLOSE all applications before signing out of the session. Disconnect Session (Switch User) also keeps your apps running. Lock Workstation: This option will lock the computer but keep all the user's programs running.

How do I unlock my desktop screen?

Press CTRL+ALT+DELETE to unlock the computer. Type the logon information for the last logged on user, and then click OK. When the Unlock Computer dialog box disappears, press CTRL+ALT+DELETE and log on normally.

What is desktop locked?

Desktop Lock is a computer security protection and access control software product. You can use it to lock computer to prevent people from accessing your private documents and resources. When the computer is locked by Desktop Lock, none can access your documents, browse your computer, or use programs on your computer.


1 Answers

The answer depends on whether you want to know if the desktop is locked now, or if you want to be notified when the desktop gets locked (and, presumably, unlocked). It also depends on how you're planning to receive said notifications.

  • If you really want a one-off test, then the answer here uses OpenDesktop() and SwitchDesktop() to open a handle to the default desktop and activate it - if this fails then it's a good sign that the desktop is locked right now.

  • If you want notification on lock/unlock, and you have a user-mode application with a window and a message pump, then you need to call WTSRegisterSessionNotification() and catch the WM_WTSSESSION_CHANGE message.

  • If you want notifications, and you're running as a Windows service, then you can register for session change events by calling SetServiceStatus() and adding SERVICE_ACCEPT_SESSIONCHANGE to dwControlsAccepted in your status structure. You will then receive callbacks to your own service control HandlerEx() function with dwControl set to SERVICE_CONTROL_SESSIONCHANGE.

like image 125
snowcrash09 Avatar answered Sep 23 '22 02:09

snowcrash09