Determine if System is Shutting Down/Restarting or Logging off
-
Is there an API call that can be used to detect if the system is Shutting down/Restarting or Logging Off. I've got a program that runs as a scheduled task, and sometimes when the user logs off, the Program Wait...End Now comes up or the "application couldn't start because the terminal is shutting down", because the scheduled task is started each 5 minutes. I want to prevent the error, is there anything I can do?
-
Is there an API call that can be used to detect if the system is Shutting down/Restarting or Logging Off. I've got a program that runs as a scheduled task, and sometimes when the user logs off, the Program Wait...End Now comes up or the "application couldn't start because the terminal is shutting down", because the scheduled task is started each 5 minutes. I want to prevent the error, is there anything I can do?
Have a look at WM_QUERYENDSESSION: WM_QUERYENDSESSION The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls the ExitWindows function. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero. After processing this message, the system sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message.
WM_QUERYENDSESSION
nSource = (UINT) wParam; // source of end-session request
fLogOff = lParam // logoff flagParameters 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. :-D Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)