2

I've been trying to use WTSEnumerateSessions to determine how many users are currently logged on, as suggested in this post.

My main problem is not understanding how to use the contents of the WTS_SESSION_INFO struct returned to determine how many users are logged on. In Windows XP Pro SP3, when a single user is logged on, I get two lots of session info;

Win Station Name: console, ID: 0
Win Station Name: RDP-Tcp, ID: 65536

In Windows 7 Ultimate (64 bit), again when a single user is logged on, I get two lots of session info:

Win Station Name: services, ID: 0
Win Station Name: console, ID: 1

Can anyone explain/point me in the direction of a resource that can explain how and why the session information differs between the two operating systems? And how can I determine how many users are logged on from this information?

Many thanks

2 Answers 2

3

Why session 0 has changed: http://msdn.microsoft.com/en-us/library/bb756986.aspx

The RDP-Tcp session with ID 65536 is a listening session -- it just listens for incoming connections.

To determine how many users are logged on, I would suggest counting the number of sessions with nonempty usernames. You can fetch a session's username using WTSQuerySessionInformation. If you are using a .NET language, you might find the Cassia library more convenient to use.

1

If you want to use this to get info on the logged in users, consider using WTSEnumerateSessionsEx, as it has some useful extra fields, including pUserName and pDomainName.

I think it's less trouble that a combo of WTSEnumerateSessions and WTSQuerySessionInformation.

1
  • 2
    Unfortunately WTSEnumerateSessionsEx is available only in Windows 7 and above.
    – Paul
    Nov 7, 2013 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.