procedure WMQUERYENDSESSON(var AMessage:TWMQueryEndSession);message WM_QUERYENDSESSION; //达到多少秒 function LeaveTimeBySeconds:Cardinal; 实现: procedure WMQUERYENDSESSON(var AMessage: TWMQueryEndSession); begin ShowMessage('要关机了'); end; function LeaveTimeBySeconds: Cardinal; var _last:tagLASTINPUTINFO; begin _last.cbSize:=SizeOf(tagLASTINPUTINFO); GetLastInputInfo(_last) ; Result := (GetTickCount-_last.dwTime) div 1000; end;