Detecting Logoff from a Service

Last reviewed: December 17, 1996
Article ID: Q151424
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

Sometimes it is handy for a service to determine whether or not a user is logged on the system. For example, there are circumstances under which the service displays a dialog box and waits for a user to respond. If this is done when no user is logged on, the service is blocked until a user logs on.

Services can be notified when a user logs off a system but not when a user logs on. A service receives a notification from the system by installing a Console Control handler. The handler receives a CTRL_LOGOFF_EVENT when the interactive user logs off the system. For more information on Console Control handlers, please refer to the Win32 SDK Online Reference.

A service can determine whether an interactive user is logged on by determining whether the process specified in the following key is running:

   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
       \Winlogon

In this key, the process specified by the value shell is launched when an interactive user logs onto a system. If this process is running, it indicates that there is an interactive user logged on. To enumerate the processes on a Windows NT system, the service needs to examine the Windows NT performance counters. For more information, please refer to either the TLIST sample on the Win32 SDK or the Win32 SDK Online References.


Additional reference words: 3.50 3.51 4.00
KBCategory: kbprg
KBSubcategory: BseService



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.