How to get the active user when multiple users are logged on in Windows?

前端 未结 2 2063
耶瑟儿~
耶瑟儿~ 2020-12-18 11:17

Suppose there are multiples users currently logged on on Windows. Say, user1 logs on, then switch user and user2 logs on, (without ma

2条回答
  •  天涯浪人
    2020-12-18 11:57

    You can call WTSGetActiveConsoleSessionId to get the terminal services (aka "fast user switching" aka "remote desktop") session ID that is currently active on the physical console.

    You can call WTSQuerySessionInformation with WTS_CURRENT_SESSION for the session identifier and WTSSessionId for WTSInfoClass to 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 WTSConnectState option to WTSQuerySessionInformation.

提交回复
热议问题