EnableExplicit #WTS_SESSION_UNLOCK = $08 Procedure WTSRegisterSessionNotification(hwnd,flags) Protected wtsapi32 Protected Res wtsapi32=OpenLibrary(#PB_Any, "wtsapi32.dll") If wtsapi32 Res = CallFunction(wtsapi32, "WTSRegisterSessionNotification", hwnd, flags) CloseLibrary(wtsapi32) ProcedureReturn Res EndIf EndProcedure Procedure WTSUnRegisterSessionNotification(hwnd) Protected wtsapi32 Protected Res wtsapi32=OpenLibrary(#PB_Any, "wtsapi32.dll") If wtsapi32 Res = CallFunction(wtsapi32, "WTSUnRegisterSessionNotification", hwnd) CloseLibrary(wtsapi32) ProcedureReturn Res EndIf EndProcedure Procedure WinCallback(hWnd, uMsg, wParam, lParam) Select uMsg Case #WM_WTSSESSION_CHANGE Select wParam Case #WTS_SESSION_UNLOCK Debug "User was logged in." EndSelect EndSelect ProcedureReturn #PB_ProcessPureBasicEvents EndProcedure If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) SetWindowCallback(@WinCallback()) WTSRegisterSessionNotification(WindowID(0), 0) Repeat Select WaitWindowEvent() Case #PB_Event_CloseWindow WTSUnRegisterSessionNotification(WindowID(0)) End EndSelect ForEver EndIf