2
votes
SELECT TotalSessions FROM Win32_TerminalService

This count is always off by 1. If there is 1 user visible on the server, the count shows 2.

This is from the MSDN

TotalSessions

    Data type: uint32
    Access type: Read-only

    The total number of sessions on the current server. This includes both connected and disconnected sessions.

I know I can just -1 from the total but is that really the correct way to handle this?

Why is it seeing the additional +1 user?

1

1 Answers

0
votes

I'm not sure but believe it's counting Session 0 as well as any other sessions you might have (console session or terminal session). As of Vista, Session 0 is a session created by the system to launch it's own system services and processes in isolation from user sessions. If you open up task manager and look at the process list, you can add a column which will show you the Session ID and you can see what's running in session 0