Platform SDK: Win32 API

The RegisterServiceProcess Function

Applications started by the system using the RunServices and RunServicesOnce keys will close when the user selects Close all programs and log on as a different user from the Shutdown dialog box. By calling the RegisterServiceProcess function, a Win32-based application can prevent itself or any other Win32-based application from being closed when the user logs off. Win32-based applications registered in this manner close only when the system is shut down.

The application should provide for different users logging on at different times during its execution. The application can distinguish between a user logging off and the system shutting down by examining the lParam parameter of the WM_QUERYENDSESSION and WM_ENDSESSION messages. If the user shuts down the system, lParam is NULL. If the user logs off, lParam is set to ENDSESSION_LOGOFF.