Console App Launched from a Service Exits When User Logs Off

Last reviewed: December 17, 1996
Article ID: Q149901
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.51 and 4.00
    

SUMMARY

Console 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.

REFERENCES

For 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
KBCategory: kbprg
KBSubcategory: BseService BseCon



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 17, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.