Shadeclan Posted March 7, 2016 Share Posted March 7, 2016 Is there a way in AutoIt to lock the screen and activate the current screen saver WITHOUT downloading and using 3rd party software? Currently, I run MonitorES which starts the screen saver after I lock my workstation but I would like to be able to do it via AutoIt alone. Basically, I'm looking for a way to ditch MonitorES, which runs continuously in the background. I am aware of the AutoIt user function _WinAPI_LockWorkStation and it does work with MonitorES but I'd like a purely AutoIt solution, if possible. If this is not possible, could this functionality be added to a future version of AutoIt? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 7, 2016 Developers Share Posted March 7, 2016 So explain what your conditions are when you want to perform _WinAPI_LockWorkStation. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Shadeclan Posted March 7, 2016 Author Share Posted March 7, 2016 When I leave my workstation, I press a certain key combination which locks the computer. MonitorES detects this condition and starts the current screensaver. Without MonitorES, it would remain on the lock screen until such time as the screen saver is scheduled to start - about 10 minutes under our current user policy. It would be ideal if a parameter could be added to _WinAPI_LockWorkStation that would start the screen saver - the default, of course, would be to not start the screen saver in order to maintain backwards compatibility. Link to comment Share on other sites More sharing options...
JohnOne Posted March 7, 2016 Share Posted March 7, 2016 Does a screensaver even work on a locked workstation? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
spudw2k Posted March 9, 2016 Share Posted March 9, 2016 Looking at the source for MonitorES, I believe the functionality should be very similar to the following (but it no workie and I can't see why ): expandcollapse popup;#AutoIt3Wrapper_Change2CUI=y #include <SendMessage.au3> Local Const $HWND_BROADCAST = 0xFFFF Local Const $WM_SYSCOMMAND = 0x112 Local Const $SC_SCREENSAVE = 0xF140 Global $bStartScreenSaver = 0 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("WM_SESSION_CHANGE_MONITOR", 200, 200); GUI to receive notification ;GUISetState() GUIRegisterMsg($WM_WTSSESSION_CHANGE, "_WM_WTSSESSION_CHANGE") DllCall("Wtsapi32.dll", "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", $NOTIFY_FOR_THIS_SESSION) While 1 If GUIGetMsg() = -3 Then ExitLoop If $bStartScreenSaver Then $bStartScreenSaver = 0 ScreenSaver() EndIf WEnd DllCall("Wtsapi32.dll", "int", "WTSUnRegisterSessionNotification", "hwnd", $hGUI) Func _WM_WTSSESSION_CHANGE($hWnd, $iMsgID, $wParam, $lParam) If $iMsgID <> $WM_WTSSESSION_CHANGE Then Return 0 Local $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." $bStartScreenSaver = 1 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 Return ConsoleWrite($sMsg & @CRLF) EndFunc Func ScreenSaver() ConsoleWrite("Starting Screensaver..." & @CRLF) sleep(1000) _SendMessage($HWND_BROADCAST, $WM_SYSCOMMAND, $SC_SCREENSAVE, 0) EndFunc Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted March 9, 2016 Share Posted March 9, 2016 All I do is check "On resume, display logon screen" in my screen saver settings. This effectively locks the computer if your screen saver starts. My script is them simply, launch screensaver. #Include <WinAPI.au3> #Include <WindowsConstants.au3> Global Const $SC_SCREENSAVE = 0XF140 _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0) spudw2k and Shadeclan 2 Link to comment Share on other sites More sharing options...
JohnOne Posted March 9, 2016 Share Posted March 9, 2016 HotkeySet _WinAPI_LockWorkStation Run AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Shadeclan Posted March 18, 2016 Author Share Posted March 18, 2016 (edited) Spudw2k: A noble effort - thanks. JohnOne: I was aware of the LockWorkStation function but, without MonitorES, it simply locks the workstation without activating the screensaver. ViciousXUSMC: Your code works great - this resolves my issue. Thanks. I added it to WinAPISys.au3 in my copy of AutoIT under your name as _WinAPI_StartScreenSaver, no return value. I should probably save a copy of WinAPISys in case it gets wiped out by a future AutoIT upgrade. Thanks again. Edited March 18, 2016 by Shadeclan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now