Jump to content
Sign in to follow this  

Detect Locked/Unlocked PC when it in Remote Desktop

Recommended Posts


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


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
    If $iLocked Then
        Return 1
        Return 0
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!

Share this post

Link to post
Share on other sites

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.


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

Share this post

Link to post
Share on other sites

I will check it out.


Share this post

Link to post
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
Sign in to follow this