PRB: WTSEnumerateSessions Shows Session 0 as Disconnected When No User Is Logged on (307642)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows XP
    • the operating system: Microsoft Windows Server 2003

This article was previously published under Q307642

SYMPTOMS

The WTSEnumerateSessions function can be used to determine the state of each session on a computer that is running Terminal Services. A state of WTSDisconnected typically indicates that a user is logged on to the session but the Terminal Services client is currently disconnected from the server. On Windows XP, however, the state for session 0 can be misleading because it will be WTSDisconnected even if there is no user logged on.

CAUSE

Session 0 is distinguished from other sessions by the fact that all Windows XP services run in session 0. Therefore, this session will never truly be in an idle state. By convention, the operating system reports the state for session 0 as WTSDisconnected if there is no user logged on.

RESOLUTION

To accurately determine if a user has logged on to session 0, you can use the WTSQuerySessionInformation() function with the WTSUserName information class. If there is no user logged on, the returned buffer will contain an empty string. Otherwise, it will contain the name of the logged-on user.

STATUS

This behavior is by design.

Modification Type:MinorLast Reviewed:10/17/2003
Keywords:kbAPI kbKernBase kbprb kbTermServ KB307642