Lej Posted August 14, 2009 Share Posted August 14, 2009 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 Link to comment Share on other sites More sharing options...
Yashied Posted August 14, 2009 Share Posted August 14, 2009 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 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Lej Posted August 14, 2009 Author Share Posted August 14, 2009 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. Link to comment Share on other sites More sharing options...
Yashied Posted August 14, 2009 Share Posted August 14, 2009 (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 August 14, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Lej Posted August 14, 2009 Author Share Posted August 14, 2009 (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 August 14, 2009 by Lej Link to comment Share on other sites More sharing options...
Yashied Posted August 14, 2009 Share Posted August 14, 2009 (edited) Congratulations, good solution. My bad today. >_< Edited August 14, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Lej Posted August 14, 2009 Author Share Posted August 14, 2009 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. 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