tags:

views:

430

answers:

1

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

A: 

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.

Dan Ports