Console App Launched from a Service Exits When User Logs OffLast reviewed: December 17, 1996Article ID: Q149901 |
The information in this article applies to:
SUMMARYConsole applications contain a default console control handler. The console control handler function is called by the system when a process receives a CTRL_C, CTRL_BREAK, CTRL_CLOSE, CTRL_LOGOFF, or CTRL_SHUTDOWN signal. By default, when the console control handler receives any one of these signals, it calls ExitProcess(). When a console application is launched from a service, the application receives a modified default console control handler. The modified handler does not call ExitProcess() for the CTRL_LOGOFF signal. This allows a console application to continue running when a user logs off the system. This corresponds with Windows NT services that run when no user is logged onto the system. If the console application being launched from a service installs its own console control handler, this handler is called before the default handler. If the installed handler calls ExitProcess() as a result of a CTRL_LOGOFF signal, the console application exits when the user logs off the system. Using any third party libraries or DLLs could cause a console control handler to be installed for an application. If installed, this handler overrides the default handler, causing the application to exit when receiving a CTRL_LOGOFF signal. For example, if you install a SIGBREAK handler via the C run-time function signal(), the function installs a handler which overrides the default handler. This causes the application to exit when receiving a CTRL_LOGOFF event even though it was launched from a service. This problem can be resolved by either not installing the SIGBREAK handler or by installing another console control handler after the call to signal(). The new console control handler must intercept the CTRL_LOGOFF event and just return TRUE for the application not to exit.
REFERENCESFor more information on console control handlers, please see the Console Overview in the Win32 SDK documentation.
|
Additional reference words: 3.50 3.51 4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |