当windows要关机的时候会向各个应用程序发一个消息:WM_QUERYENDSESSION
WM_QUERYENDSESSION
nSource = (UINT) wParam; ; ;// source of end-session request
fLogOff = lParam ; ; ; ; ; ;// logoff flag
;
Parameters
nSource
Reserved for future use.
fLogOff
Value of lParam. Indicates whether the user is logging off or shutting down the system. Supported values include: ENDSESSION_LOGOFF.
Return Values
If an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE. ;
你可以在程序里面拦截这个消息。在处理过程里面把系统时间记录下来写入注册表不就是了么!