Detecting Logoff from a Service

ID: Q151424


The information in this article applies to:


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 query words: 3.50


Keywords          : kbKernBase kbService kbGrpKernBase 
Version           : 3.50 3.51 4.00
Platform          : NT WINDOWS 
Issue type        : 

Last Reviewed: March 10, 1999