Script: Show a message when you log in
This script shows a gui fading in when the user logs in, with the message: Welcome back, (username).
DllCall("wtsapi32.dll\WTSRegisterSessionNotificationEx", "Ptr", 0, "Ptr", A_ScriptHwnd, "UInt", 1)
OnMessage(0x02B1, "WM_WTSSESSION_CHANGE")
WM_WTSSESSION_CHANGE(wParam, lParam) {
static WTS_SESSION_UNLOCK := 0x8
if (wParam = WTS_SESSION_UNLOCK) {
;; show an animated welcome screen on log in
WelcomeTrayTip()
}
}
WelcomeTrayTip() {
static GuiCreated := 0
static HwndWelcomeScreen
static MonRight, MonBottom
if !GuiCreated {
GuiCreated := 1
Gui, WelcomeScreen:New, +AlwaysOnTop -Caption +ToolWindow +HwndHwndWelcomeScreen +LastFound -DPIScale +E0x20 ; Clickthrough=E0x20
Gui, WelcomeScreen:Margin, 30, 25
Gui, WelcomeScreen:Font, s30, Segoe UI SemiBold
Gui, WelcomeScreen:Color, 1A1A1A
Gui, WelcomeScreen:Add, Text, y20 cWhite, Welcome back, %A_UserName% ; make a text control showing welcome back, (username)
WinSet, Transparent, 0 ; set gui transparent
SysGet, P, MonitorPrimary ; get primary monitor number
SysGet, Mon, MonitorWorkArea, % P ; get size of primary monitor
Gui, WelcomeScreen:Show, Hide ; Show gui hidden
WinGetPos, X, Y, W, H ; get pos of gui
WinMove, % MonRight - W - 10, % MonBottom - H - 10 ; move gui to bottom right
WinSet, Region, 0-0 W%W% H%H% R20-20 ; round corners
}
Gui, WelcomeScreen:Show, NA
bf := Func("AnimateFadeIn").Bind(HwndWelcomeScreen)
SetTimer, %bf%, -200
}
AnimateFadeIn(hwnd) {
static Value := 0
WinSet, Transparent, % Value+=15, % "ahk_id" hwnd
if (Value >= 255) { ; if gui is fully opaque
Value := 0 ; reset transparency value
bf := Func("AnimateFadeOut").Bind(hwnd) ; make bound function to fade out
SetTimer, %bf%, -3000 ; run bound function in 3 seconds
} else {
bf := Func("AnimateFadeIn").Bind(hwnd) ; create bound functiion to fade in
SetTimer, %bf%, -15 ; rerun bound function until gui is fully opaque
}
}
AnimateFadeOut(hwnd) {
static Value := 255
WinSet, Transparent, % Value-=15, % "ahk_id" hwnd
if (Value <= 0) { ; if gui invisible
Value := 255 ; reset transparency value
Gui, %hwnd%:Hide ; hide gui when finished
} else {
bf := Func("AnimateFadeOut").Bind(hwnd) ; create bound functiion to fade out
SetTimer, %bf%, -15 ; rerun bound function until gui is transparent
}
}
Posted Oct 31, 2022, 6:19 AM UTC
44
But that will only show the message when users unlock the PC.
Shouldn't be the
WTS_SESSION_LOGONconstant and the script running as service (boot, no delay to catch the session notification change event)?WTS_SESSION_UNLOCKworks for me. I usually don't log off. How do you run the script as a service?I don't log off much, either. But I use the
WTSRegisterSessionNotification()function in conjunction with other methods to check for different triggers to clear my master password from memory.What I meant is that if the
_UNLOCKmessage was triggered on logon and not just on unlock? But makes sense if it is triggered given that a logon does an unlock :PAs for the service... converting the script to executable and with just
sc createshould be enough, right? Perhaps setting the flag to be run as interactive and shared process, given that AHK depends on both a user account and the GUI. But I never tested this, and one might run into issues with theLocalSystemaccount.