I think,
I am trying to get a list of users who are currently logged in.
you want to list all users who are registered online, that is, have a desktop, etc. So this is the physical console and RDP connections.
So, you have to distinguish between "logged in interactively" and "logged in" due to a call to LogonUser . With LogonUser you can start a process in an interactive user session or start a batch process. LSA returns all these users.
Use WTSEnumerateSessions and check if the session is in the state you need.
source share