Suppose there are multiples users currently logged on on Windows. Say, user1 logs on, then switch user and user2 logs on, (without making user1 log off). Suppose there is an app which runs when user logs on. There are two users user1 and user2 logged on, with user2 as the active user, and there are two apps.
My question is: How does the app know whether its corresponding user is active or not? I.e., app in user2 domain determines that its user is active, while app in user1 domain determines its user is currently inactive. Thanks!
You can call
WTSGetActiveConsoleSessionIdto get the terminal services (aka “fast user switching” aka “remote desktop”) session ID that is currently active on the physical console.You can call
WTSQuerySessionInformationwithWTS_CURRENT_SESSIONfor the session identifier andWTSSessionIdforWTSInfoClassto get the terminal services session ID for the current process.If the active session ID and the current process session ID are the same, the user corresponding to the current process has the active session on the physical console.
If what you want to know is whether the session that the current process is running in is active (but not necessarily on the physical console) you can instead use the
WTSConnectStateoption toWTSQuerySessionInformation.