Jump to content

Detect Locked/Unlocked PC when it in Remote Desktop


YoniB
 Share

Recommended Posts

Here's the function that I use (typically in a While... Wend loop, which should suit your requested usage well):

CODEGlobal Const $DESKTOP_SWITCHDESKTOP = 0x100

Func _CheckLocked()
    $hLockedDLL = DllOpen("user32.dll")
    $hDesktop = DllCall($hLockedDLL, "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
    $ret = DllCall($hLockedDLL, "int", "SwitchDesktop", "int", $hDesktop[0])
    DllCall($hLockedDLL, "int", "CloseDesktop", "int", $hDesktop[0])

    If $ret[0] = 0 Then
        $iLocked = 1
    ElseIf $ret[0] = 1 Then
        $iLocked = 0
    EndIf
    
    DllClose($hLockedDLL)
    
    If $iLocked Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Hi !

I tried 'Monamo' code above and it's working great for local unlocked desktop.

But when someone connect remotely (by Remote Desktop), the status is 'Unlocked' even if he closed the session (without manually unlocking), So despite that no one is connected to the pc the status is 'Unlocked'.

Why it behaving like that?

Any solution for that?

Thanks a lot!

Link to comment
Share on other sites

  • Developers

With RDP you will logon to the remote pc/server thus if the session is already running for that account it will be activated from whatever state and the desktop will be shown. When there is no User session running for the Account used, it will start a new session for that account.

When you want to takeover the screeen/keyboard without changing the system state you will have to use something like VNC.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...