#Persistent
DetectHiddenWindows, on
hwnd := WinExist("Ahk_PID " DllCall("GetCurrentProcessId"))
;Reason message
DllCall("ShutdownBlockReasonCreate", "Uint", hwnd, "Str", "Saving ramdisk files")
;Get shutdown message as late as possible
DllCall("kernel32.dll\SetProcessShutdownParameters", UInt, 0x100, UInt, 0)
;Listen for shutdown message
OnMessage(0x11, "WM_QUERYENDSESSION")
Return