escape75 wrote: Mon Jan 12, 2026 9:27 pm
... but I think I have found a solution via #WM_WTSSESSION_CHANGE & #WTS_SESSION_UNLOCK
Yes, I tried it, it works after WTSRegisterSessionNotification(), but it seems to be only in administrator mode!
Code: Select all
Enumeration
#Window
#Wtsapi32Lib
#Timer
EndEnumeration
#WTS_SESSION_LOCK = $7
#WTS_SESSION_UNLOCK = $8
Prototype pWTSRegisterSessionNotification(hWnd, dwFlags)
Prototype pWTSUnRegisterSessionNotification(hWnd)
Procedure Detect(hWnd, uMsg, wParam, lParam)
If uMsg = #WM_WTSSESSION_CHANGE
Select wParam
Case #WTS_SESSION_LOCK
Debug FormatDate("%hh:%ii:%ss", DateUTC()) + " - #WTS_SESSION_LOCK"
Case #WTS_SESSION_UNLOCK
Debug FormatDate("%hh:%ii:%ss", DateUTC()) + " - #WTS_SESSION_UNLOCK"
AddWindowTimer(#Window, #Timer, 1000)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#Window, 0, 0, 300, 70, "Test", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
SetWindowCallback(@Detect(), #Window)
If OpenLibrary(#Wtsapi32Lib, "Wtsapi32.dll")
Define WTSRegisterSessionNotification_.pWTSRegisterSessionNotification = GetFunction(#Wtsapi32Lib, "WTSRegisterSessionNotification")
WTSRegisterSessionNotification_(WindowID(#Window), 0)
EndIf
Repeat
Define Event = WaitWindowEvent()
If Event = #PB_Event_Timer And EventTimer() = #Timer
Debug FormatDate("%hh:%ii:%ss", DateUTC()) + " - Session Unlock"
RemoveWindowTimer(#Window, #Timer)
EndIf
Until Event = #PB_Event_CloseWindow
If IsLibrary(#Wtsapi32Lib)
Define WTSUnRegisterSessionNotification_.pWTSUnRegisterSessionNotification = GetFunction(#Wtsapi32Lib, "WTSUnRegisterSessionNotification")
WTSUnRegisterSessionNotification_(WindowID(#Window))
CloseLibrary(#Wtsapi32Lib)
EndIf