WTSQuerySessionInformation and WTSConnectState

Posted on 2006-05-30
Last Modified: 2013-12-03
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?
Question by:rtsh
    LVL 3

    Accepted 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.

    LVL 1

    Author Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now