• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2078
  • Last Modified:

WTSQuerySessionInformation and WTSConnectState

I've written some code in C# to loop through the results of WTSEnumerateSessions and record the names of all users, together with the connection state.  The aim is to log the amount of time individual users spend actually using a particular shared Windows XP machine.

Whilst I do see a change in state between WTSDisconnected and WTSActive as I switch users, I'd expect to see WTSDisconnected for *all* users if the machine is at the Windows XP friendly logon screen.

So, the question is:  How can I tell if the computer is at the Windows XP logon screen, or how can I tell if a session that's WTSActive isn't actually active?
1 Solution
I don't think there is an API that you can call to directly tell you this. Instead, you need to use WTSRegisterSessionNotification().

This will send you a WM_WTSSESSION_CHANGE message with the status code of WTS_SESSION_LOCK and WTS_SESSION_UNLOCK as you switch to and from the XP logon screen. It also gives you a pointer to the WTSSESSION_NOTIFICATON structure containing the session id, which should be the same as the one you get when you enumrate sessions.

rtshAuthor Commented:

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now