AutoIt:自动锁屏

2014-01-14  籽藤 

这段autoIt代码可以另存为.au3文件,直接运行在已安装autoIt的环境中。

效果:跟手动按了Windows+L键进行的锁屏效果一样,而不是《AutoHotKey:锁屏-解屏》这种模拟的锁屏效果。
再搞个定时任务,‘自动锁屏’就轻松搞定了  

Global Const $NOTIFY_FOR_THIS_SESSION = 0x0
Global Const $NOTIFY_FOR_ALL_SESSIONS = 0x1
Global Const $WM_WTSSESSION_CHANGE = 0x2B1

Global Const $WTS_CONSOLE_CONNECT = 0x1
Global Const $WTS_CONSOLE_DISCONNECT = 0x2
Global Const $WTS_REMOTE_CONNECT = 0x3
Global Const $WTS_REMOTE_DISCONNECT = 0x4
Global Const $WTS_SESSION_LOGON = 0x5
Global Const $WTS_SESSION_LOGOFF = 0x6
Global Const $WTS_SESSION_LOCK = 0x7
Global Const $WTS_SESSION_UNLOCK = 0x8
Global Const $WTS_SESSION_REMOTE_CONTROL = 0x9

Global $hGUI = GUICreate("Message Sink", 400, 600); GUI to receive notification
Global $sMsg = "$hGUI = " & $hGUI & @CRLF
Global $ctrlEdit = GUICtrlCreateEdit($sMsg, 10, 10, 380, 580)
GUISetState()

GUIRegisterMsg($WM_WTSSESSION_CHANGE, "_WM_WTSSESSION_CHANGE")
DllCall("Wtsapi32.dll", "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", $NOTIFY_FOR_THIS_SESSION)
DllCall("Kernel32.dll", "none", "Sleep", "dword", 1000)
DllCall("User32.dll", "int", "LockWorkStation")
DllCall("User32.dll", "int", "UNLockWorkStation")
While 1
    If GUIGetMsg() = -3 Then ExitLoop
WEnd
DllCall("Wtsapi32.dll", "int", "WTSUnRegisterSessionNotification", "hwnd", $hGUI)

Func _WM_WTSSESSION_CHANGE($hWnd, $iMsgID, $wParam, $lParam)
    $sMsg &= @CRLF & @HOUR & ":" & @Min & ":" & @SEC & " = "
    Switch $wParam
        Case $WTS_CONSOLE_CONNECT
            $sMsg &= "A session was connected to the console terminal."
        Case $WTS_CONSOLE_DISCONNECT
            $sMsg &= "A session was disconnected from the console terminal."
        Case $WTS_REMOTE_CONNECT
            $sMsg &= "A session was connected to the remote terminal."
        Case $WTS_REMOTE_DISCONNECT
            $sMsg &= "A session was disconnected from the remote terminal."
        Case $WTS_SESSION_LOGON
            $sMsg &= "A user has logged on to the session."
        Case $WTS_SESSION_LOGOFF
            $sMsg &= "A user has logged off the session."
        Case $WTS_SESSION_LOCK
            $sMsg &= "A session has been locked."
        Case $WTS_SESSION_UNLOCK
            $sMsg &= "A session has been unlocked."
        Case $WTS_SESSION_REMOTE_CONTROL
            $sMsg &= "A session has changed its remote controlled status."
    EndSwitch
    $sMsg &= @CRLF & "$hWnd = " & $hWnd & @CRLF & _
            "$iMsgID = 0x" & Hex($iMsgID, 8) & @CRLF & _
            "$wParam = " & $wParam & @CRLF & _
            "$lParam = " & $lParam & @CRLF
    ControlSetText($hGUI, "", $ctrlEdit, $sMsg)
EndFunc

594°/5948 人阅读/0 条评论 发表评论

登录 后发表评论