enneract Posted July 16, 2010 Share Posted July 16, 2010 I hate to start multiple topics, but this is far enough afield from my other to warrant it, I think. I'm trying to find a way to detect the presence of the ctrl-alt-del lock screen, preferably in a way that doesn't require polling, so that I can delay components of script execution until the screen is no longer present. I've been searching for the past two hours or so, with only a reference to looking for the presence of a window titled "Program Manager" to detect if the screen is not present, but this doesn't seem to do anything. Alternatively, a way to register WM_DISPLAYCHANGE and preform file copy operations while the lock screen is present would also work very well. Link to comment Share on other sites More sharing options...
KaFu Posted July 16, 2010 Share Posted July 16, 2010 (edited) Now don't ask me about the event "Global Const $EVENT_OPEN_DESKTOP_CHANGED = 0x0020". Found it by trial an error, otherwise it seems to be undocumented , hell, it could even mean something completely different ... expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: KaFu Script Function: Use a WinEventHook to detect a Desktop Change #ce ---------------------------------------------------------------------------- HotKeySet("{ESC}", "_Exit") #region ; WinEventHook ; Event Constants ; http://msdn.microsoft.com/en-us/library/ms697187.aspx ; http://msdn.microsoft.com/en-us/library/dd318066(VS.85).aspx ; http://mwinapi.sourceforge.net/doc/html/T_ManagedWinapi_Accessibility_AccessibleEventType.htm ; http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/accessibility/AccConst.html Global Const $EVENT_OPEN_DESKTOP_CHANGED = 0x0020 ; Undocumented? Found by trial&error... $h_DLL_User32 = DllOpen("User32.dll") $h_WinEventHook_Proc = DllCallbackRegister("_WinEventHook_Proc", "none", "hwnd;int;hwnd;long;long;int;int") If @error Then MsgBox(16 + 262144, "Error", "DllCallbackRegister(_WinEventHook_Proc) did not succeed. FFH will exit now.") Exit EndIf $h_Hook = _WinEventHook_Set(0x0020, 0x0020, $h_DLL_User32) If @error Then MsgBox(16 + 262144, "Error", "_WinEventHook_Set() did not succeed. FFH will exit now.") Exit EndIf OnAutoItExitRegister("_WinEventHook_UnSet") #endregion ; WinEventHook while 1 sleep(10) wend #region ; WinEventHook Functions Func _WinEventHook_Proc($h_Hook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime) ;ConsoleWrite($hWnd & @TAB & $idObject & @CRLF) ConsoleWrite(TimerInit() & @tab & hex($iEvent,4) & @tab & "IsDesktopLocked()" & @tab & IsDesktopLocked() & @crlf) EndFunc ;==>_WinEventHook_Proc Func _WinEventHook_Set($iEventMin, $iEventMax, $hDLLUser32) Local $aRet Local Const $WINEVENT_OUTOFCONTEXT = 0x0 Local Const $WINEVENT_SKIPOWNPROCESS = 0x2 If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll" $aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _ "uint", $iEventMin, _ "uint", $iEventMax, _ "hwnd", 0, _ "ptr", DllCallbackGetPtr($h_WinEventHook_Proc), _ "int", 0, _ "int", 0, _ "uint", $WINEVENT_OUTOFCONTEXT) ; BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS) If @error Then Return SetError(@error, 0, 0) Return $aRet[0] EndFunc ;==>_WinEventHook_Set Func _WinEventHook_UnSet() If $h_WinEventHook_Proc Then DllCallbackFree($h_WinEventHook_Proc) EndIf If $h_Hook Then DllCall($h_DLL_User32, "int", "UnhookWinEvent", "hwnd", $h_Hook) If $h_DLL_User32 Then DllClose($h_DLL_User32) EndFunc ;==>_WinEventHook_UnSet #endregion ; WinEventHook Functions Func IsDesktopLocked() Local $hDesktop Local $iRet Local $iRC Local $sMsg Local Const $DESKTOP_SWITCHDESKTOP = 0x100 $hDesktop = DllCall("User32.dll", "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP) $iRet = DllCall("User32.dll", "int", "SwitchDesktop", "int", $hDesktop[0]) If IsArray($iRet) Then If $iRet[0] = 0 Then $iRC = 1 ElseIf $iRet[0] = 1 Then $iRC = 0 EndIf Else EndIf DllCall("User32.dll", "int", "CloseDesktop", "int", $hDesktop[0]);<-- handle returned by "OpenDesktop" ;$iRet = DllCall("User32.dll", "int", "CloseDesktop", "int", $iRet[0]) Return ($iRC) EndFunc ;==>IsDesktopLocked Func _Exit() Exit EndFunc ;==>_Exit Edited July 16, 2010 by KaFu telmob 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
enneract Posted July 16, 2010 Author Share Posted July 16, 2010 I don't understand that code, at all. I can copy and paste with the best of them, but I don't even see how that code interfaces with anything? I see the hook, but I don't understand what triggers it, nor how I can reference it. Can you shed some light, or point me in the direction of some reading material? Link to comment Share on other sites More sharing options...
Yashied Posted July 17, 2010 Share Posted July 17, 2010 Maybe you say us why you need it? 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...
enneract Posted July 17, 2010 Author Share Posted July 17, 2010 Maybe you say us why you need it? I need to delay operation of a script until the lock\welcome screen is no longer present. The script's purpose is to counteract the lack of Win7's ability to use specific logon backgrounds for widescreen resolutions, and applies backgrounds based on whatever arbitrary resolution the desktop is set to, using WM_DISPLAYCHANGE to notice when the change happens. However, none of this seems to work if the logon\lock\welcome screen is up when the display change takes place, so I need to detect when that happens and poll the desktop resolution when the screen is exited. #NoTrayIcon $path = "C:\Windows\System32\oobe\info\backgrounds\" $last = @DesktopHeight Func On_Start() GUICreate("", 0,0,0,0) GUIRegisterMsg(0x007E, "Display_Changed") Do_Copy() EndFunc Func Do_Copy() If NOT FileCopy($path & "background" & @DesktopWidth & "x" & @DesktopHeight & ".jpg", $path & "backgroundDefault.jpg", 1) Then SoundPlay(@WindowsDir & "\media\Windows Error.wav",1) EndIf EndFunc Func Display_Changed() If $last <> @DesktopHeight Then Do_Copy() $last = @DesktopHeight EndIf EndFunc On_Start() While 0 < 1 WEnd Link to comment Share on other sites More sharing options...
KaFu Posted July 17, 2010 Share Posted July 17, 2010 Can you shed some light, or point me in the direction of some reading material?Copy the code to SciTE, run the code, lock your desktop and watch the console... you'll see yourself where to log in... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
enneract Posted July 17, 2010 Author Share Posted July 17, 2010 Copy the code to SciTE, run the code, lock your desktop and watch the console... you'll see yourself where to log in...Oooh, I see. _WinEventHook_Proc() is actions to be preformed on the hook.Gotcha. Thanks a bunch, KaFu. Link to comment Share on other sites More sharing options...
KaFu Posted July 17, 2010 Share Posted July 17, 2010 Yep, _WinEventHook_Proc() is fired only, when a Desktop Switch is detected , you're welcome, I love tinkering around, just discovering the power of the hooks (sounds more like Peter Pan )... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 26, 2011 Share Posted February 26, 2011 Recalled this thread, and wanted to figure out what was going on, so I looked deeper and found the 'undocumented' message KaFu is hooking really is documented (the links give you the names of all the events, but not the numbers). The numbers are defined in WinUser.h, however. And the one you found KaFu reads as this: #define EVENT_SYSTEM_DESKTOPSWITCH 0x0020 The only issue with this is, it only works on Vista+ (its surrounded by a version check (v. 0x0600 min. [Vista]) during preprocessing). Anyway, just thought I'd clean up that bit of confusion and document what I came across. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
KaFu Posted February 26, 2011 Share Posted February 26, 2011 (edited) Your clarification is always appreciated ... seems like a bad habit of mine, saying something is undocumented even if it is (see also about the /u @comspec switch ), I have to be more careful with that term . Edited February 26, 2011 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 26, 2011 Share Posted February 26, 2011 No problem.. we're all fumbling our way (at some stage or another) through the huge Windows programming interface and its various iterations. By the way - using that hook for 'EVENT_SYSTEM_DESKTOPSWITCH' also allows one to detect when UAC has locked the screen. I hadn't noticed that because I kept UAC at the 2nd-to-lowest setting (Windows 7), which only gives a query messagebox. However, any higher - or if running on Vista - and that event fires, along with the faded background/locked desktop. Having a function that detects 3 state changes is awesome, and I'm sure that will be of good use somewhere along the line. For XP, I think the WM_WTSSESSION_CHANGE message will suffice as an alternative to detect user-switching, workstation locking, and logging off. At the lowest end (of NT-based O/S's), Win 2000 would need Terminal Services installed, which (I believe) would enable that message. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) 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