Sign in to follow this  
Followers 0
sublimnl

Detect if workstation is locked

5 posts in this topic

Like the title says, I need to determine whether the workstation is locked and then wait to proceed until it is unlocked. Anyone know of a way to do it?

While 1
If <somehow-check-if-computer-is-locked> Then
   Sleep(250)
Else
   ExitLoop
EndIf
WEnd

Share this post


Link to post
Share on other sites



this could cause a few false positives I think, but it worked for me.

While 1
    Sleep(1000)
    $title = WinGetTitle( "" )
    $text = WinGetText( "" )
    If StringInStr ( $text, "Program Manager" ) <> 0 and $title = "" Then
    FileWrite( "test.log", @HOUR & ":" & @MIN & ":" & @SEC & " - " & "workstation locked" & @CRLF)
    EndIf
WEnd

additionally, if your setup is triggering false positives with the test script above, try including the AutoItSetOption("WinDetectHiddenText",1) option with flag set to 1 (read hidden text) and include more information to test with the StringInStr function.

Hope this helps :rolleyes:

Share this post


Link to post
Share on other sites

Thanks for that. I will give it a shot!

Share this post


Link to post
Share on other sites

Original code by tonedeaf.

HotKeySet("{ESC}", "_Exit")

$DESKTOP_SWITCHDESKTOP = 0x100

While 1
    If _IsLocked() Then
        ConsoleWrite("Workstation is locked." & @CR)
    Else
        ConsoleWrite("Workstation not locked." & @CR)
    EndIf
    Sleep(1000)
WEnd

Func _IsLocked()
    $hDesktop = DllCall("User32.dll", "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
    $ret = DllCall("User32.dll", "int", "SwitchDesktop", "int", $hDesktop[0])
    DllCall("User32.dll", "int", "CloseDesktop", "int", $ret[0])

    If $ret[0] Then
        Return SetError(0, 0, 0)
    Else
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_IsLocked

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Can the above code be modified to also detect if a remote PC is locked or not? Is there a way to do that?

Edited by Furek86

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  
Followers 0