"Computer ist gesperrt" ermitteln

  • Tag

    Ist es möglich mit AutoIt zu ermitteln ob der PC gesperrt wurde? Ziel ist es dass eine Anwendung sich pausiert sobald der Computer gesperrt wird (über Win + L order Ctrl + Alt + Delete und dann auf Computer sperren). Sobald der PC dann wieder läuft, soll das Script fortfahren? Gibt es eine Möglichkeit das zu ermitteln? Habe durch Google nichts brauchbares gefunden.

    Einmal editiert, zuletzt von ahatius (6. November 2009 um 16:01)

    • Offizieller Beitrag
    Spoiler anzeigen
    [autoit]

    Global Const $DESKTOP_ENUMERATE = 0x40
    Global Const $SPI_GETSCREENSAVERRUNNING = 114
    Global Const $DESKTOP_SWITCHDESKTOP = 0x100

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}", "_Terminate")
    AdlibEnable("IsDeskTopLocked", 500)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func IsDeskTopLocked()
    Local $p_lngHwnd, $p_lngRtn, $p_lngErr, $p_lngScreenSaver, $p_blnIsScreenSaver

    [/autoit] [autoit][/autoit] [autoit]

    ;~ ' ------------------------------------------
    ;~ ' First check for screen saver one of 2 ways,
    ;~ ' based of OS
    ;~ ' ------------------------------------------
    If @OSTYPE = "WIN32_WINDOWS" Then
    ;~ ' ---------------------------------------
    ;~ ' Pre W2K -- Note, will only be TRUE if
    ;~ ' the "Password Protected" box is
    ;~ ' checked.
    ;~ ' ---------------------------------------
    $p_lngHwnd = DllCall("user32.dll", "int", "OpenDesktopA", "str", "screen-saver", "int", 0, "int", False, "int", $DESKTOP_ENUMERATE)
    If $p_lngHwnd[0] <> 0 Then
    $p_blnIsScreenSaver = True
    Else
    $p_blnIsScreenSaver = False
    EndIf
    Else
    ;~ ' ---------------------------------------
    ;~ ' W2K+ -- Will determine if screen saver
    ;~ ' is running whether or not the
    ;~ ' "Password Protected" box is checked
    ;~ ' ---------------------------------------
    $p_lngRtn = DllCall("user32.dll", "int", "SystemParametersInfoA", "int", $SPI_GETSCREENSAVERRUNNING, "int", 0, "int", $p_lngScreenSaver, "int", 0)
    If $p_lngRtn[0] = 0 Then
    ConsoleWrite("+>Error detecting screen saver" & @LF)
    Else
    $p_blnIsScreenSaver = $p_lngScreenSaver
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;~ ' ------------------------------------------
    ;~ ' If screen saver is *not* running, then
    ;~ ' check for locked workstation
    ;~ ' ------------------------------------------
    If $p_blnIsScreenSaver Then
    If @OSTYPE = "WIN32_WINDOWS" Then
    ConsoleWrite("Screen saver is running..., Handle #" & $p_lngHwnd[0] & @LF)
    $p_lngHwnd = DllCall("user32.dll", "int", "CloseDesktop", "int", $p_lngHwnd[0])
    Else
    ConsoleWrite("Screen saver is running on W2K+" & @LF)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Else
    $p_lngHwnd = DllCall("user32.dll", "int", "OpenDesktopA", "str", "Default", "int", 0, "int", False, "int", $DESKTOP_SWITCHDESKTOP)

    [/autoit] [autoit][/autoit] [autoit]

    If $p_lngHwnd[0] = 0 Then
    ConsoleWrite("Error with OpenDesktop" & @LF)

    [/autoit] [autoit][/autoit] [autoit]

    Else
    $p_lngRtn = DllCall("user32.dll", "int", "SwitchDesktop", "int", $p_lngHwnd[0])
    $p_lngErr = _GetLastErrorMessage()

    [/autoit] [autoit][/autoit] [autoit]

    If $p_lngRtn[0] = 0 Then
    If $p_lngErr = 0 Then
    ConsoleWrite("! Desktop is locked" & @LF)
    Else
    ConsoleWrite("Error with SwitchDesktop" & @LF)
    EndIf
    Else
    ConsoleWrite("Not locked!" & @LF)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $p_lngHwnd = DllCall("user32.dll", "int", "CloseDesktop", "int", $p_lngHwnd[0])

    [/autoit] [autoit][/autoit] [autoit]

    EndIf
    EndIf
    EndFunc ;==>IsDeskTopLocked

    [/autoit] [autoit][/autoit] [autoit]

    Func _Terminate()
    Exit
    EndFunc ;==>_Terminate

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================
    ; _GetLastErrorMessage($DisplayMsgBox="")
    ; Format the last windows error as a string and return it
    ; if $DisplayMsgBox <> "" Then it will display a message box w/ the error
    ; Return Window's error as a string
    ;===============================================
    Func _GetLastErrorMessage($DisplayMsgBox = "")
    Local $ret, $s
    Local $p = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Return ""

    [/autoit] [autoit][/autoit] [autoit]

    $ret = DllCall("Kernel32.dll", "int", "GetLastError")

    [/autoit] [autoit][/autoit] [autoit]

    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
    "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
    "ptr", 0, _
    "int", $ret[0], _
    "int", 0, _
    "ptr", DllStructGetPtr($p), _
    "int", 4096, _
    "ptr", 0)
    $s = DllStructGetData($p, 1)
    If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s)
    Return $s
    EndFunc ;==>_GetLastErrorMessage

    [/autoit]
    [autoit]

    While 1
    Sleep(1000)
    If _isWorksatationLocked() Then ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " - " & "workstation locked" & @CRLF)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func _isWorksatationLocked()
    If StringInStr(WinGetText(""), "Program Manager") <> 0 And WinGetTitle("") = "" Then Return 1
    Return 0
    EndFunc ;==>_isWorksatationLocked

    [/autoit]