Jump to content

Recommended Posts

Posted

So, I want to make a script that locks my workstation (Win XP) and starts the screensaver.

I couldn't get it to work using the user32.dll LockWorkStation function but for some reason it did work with Send("#l") (win+l is hotkey for locking in XP).

However the Windows Key is still pressed down in the loginscreen. Any ideas on how to fix this?

Global $user32_dll = DllOpen ("user32.dll")
Const $WM_SYSCOMMAND = 0x112
Const $SC_SCREENSAVE = 0xF140

$gui = GUICreate("",10,10,-100,-100)
$guiHandle = WinGetHandle($gui)

Send("#l")
;~ _User32_LockWorkStation()
_User32_SendMessageA($guiHandle, $WM_SYSCOMMAND, $SC_SCREENSAVE, 0x0)

DllClose($user32_dll)

;~ Func _User32_LockWorkStation()
;~  DllCall($user32_dll, "long", "LockWorkStation")
;~ EndFunc

Func _User32_SendMessageA ($hWnd, $wMsg, $wParam, $lParam)
    DllCall($user32_dll, "long", "SendMessageA", "long", $hWnd, "long", $wMsg, "long", $wParam, "long", $lParam)
EndFunc
Posted

Try this.

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

Global Const $SPI_GETSCREENSAVEACTIVE = 16
Global Const $SPI_GETSCREENSAVERRUNNING = 114
Global Const $SC_SCREENSAVE = 0xF140

$Ret = DllCall('user32.dll', 'int', 'SystemParametersInfo', 'uint', $SPI_GETSCREENSAVEACTIVE, 'uint', 0, 'int*', 0, 'uint', 0)
If $Ret[3] Then
    _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0)
EndIf

Do
    ; Check timeout
Until _IsScreenSaverAcrtive()

While 1
    Sleep(10)
    If Not _IsScreenSaverAcrtive() Then
        DllCall('user32.dll', 'int', 'LockWorkStation')
        ExitLoop
    EndIf
WEnd

Func _IsScreenSaverAcrtive()

    Local $Ret = DllCall('user32.dll', 'int', 'SystemParametersInfo', 'uint', $SPI_GETSCREENSAVERRUNNING, 'uint', 0, 'int*', 0, 'uint', 0)

    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[3]
EndFunc
Posted

Yes this works. Only one small complaint if I correctly understand what you are doing it doesn't actually lock the workstation until the screensaver is interrupted. Preferably it should be locked before or use whatever windows does when it triggers it automatically with "On resume, display Welcome screen" checked.

Posted (edited)

Yes this works. Only one small complaint if I correctly understand what you are doing it doesn't actually lock the workstation until the screensaver is interrupted. Preferably it should be locked before or use whatever windows does when it triggers it automatically with "On resume, display Welcome screen" checked.

Windows does exactly the same. Lock your computer before start the Screensaver is not possible (I think). Edited by Yashied
Posted (edited)

Think I found a workaround. I trimmed down the AutoIt file to only launch the default screensaver and compiled to "StartScreensaver.exe".

Then I made another AutoIt file to lock the computer and call the "StartScreensaver.exe"

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>
Global Const $SC_SCREENSAVE = 0xF140
_SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0)

DllCall('user32.dll', 'int', 'LockWorkStation')
Run("StartScreensaver.exe")

It locks the computer and launches the screensaver.

Edited by Lej
Posted

Thanks for the help anyway! Reading your program made my new program a lot smaller. Now if I could just figure out some way to change win+l to use my program instead of the default lock everything would be perfect.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...