Jump to content
Sign in to follow this  
YoniB

Detect Locked/Unlocked PC when it in Remote Desktop

Recommended Posts

YoniB

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!

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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
YoniB

I will check it out.

Thanks.

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  

×