INFO: Detecting Logoff from a Service (151424)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows NT 3.51
    • the operating system: Microsoft Windows NT 4.0
    • the operating system: Microsoft Windows 2000
    • the operating system: Microsoft Windows XP

This article was previously published under Q151424

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.

Modification Type:MajorLast Reviewed:3/12/2004
Keywords:kbinfo kbKernBase kbService KB151424