Jump to content

Detect if workstation is locked


Recommended Posts

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
Link to comment
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:

Link to comment
Share on other sites

  • 1 month later...
  • Moderators

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
Link to comment
Share on other sites

  • 3 years later...

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...