C++ – Getting the number of logged on users in Windows

cmfcvisual c++windows

Let's say I have 3 logged on users. I have a test application which I use to enumerate the WTS sessions on the local computer, using WTSEnumerateSessions. After that, I display the information contained in each of the returned WTS_SESSION_INFO structure.

On Windows XP, there are 3 structures displayed: Session 0, 1, and 3 (for each logged on user), with the name "Console" corresponding to the active user under which I run the test application, and an empty string as the name for the other sessions. For example, if I run the application under the first user, I get Session 0 (Console), Session 1 (), Session 2 ().

On Windows Vista, there are 5 structures displayed: Session 0 (Services), Session 1 (Console), Session 2 (), Session 3 (), Session 65536 (RDP-Tcp). On another computer with Windows Vista, I get only the first four sessions (without 65536, RDP-Tcp).

I would like to know if there is a way (better way) of finding out how many logged on users are on the local machine.

Thanks in advance!