当多个用户登录Windows时,如何获取活动用户? [英] How to get the active user when multiple users are logged on in Windows?
问题描述
假设目前有多个用户在Windows上登录。说, user1
登录,然后切换用户
和 user2
登录,(不使 user1
注销)。假设有一个应用程序在用户登录时运行。有两个用户 user1
和 user2
登录, user2
作为活动用户,并且有两个应用程序。
我的问题是:应用程序如何知道其相应的用户是否活动?即, user2
域中的应用程序确定其用户处于活动状态,而 user1
域中的应用程序确定其用户当前处于非活动状态。感谢!
您可以致电 WTSGetActiveConsoleSessionId
获取终端服务(又名快速用户切换 远程桌面)当前在物理控制台上处于活动状态的会话ID。
您可以调用 WTSQuerySessionInformation
, WTS_CURRENT_SESSION
为会话标识符和 WTSSessionId
为 WTSInfoClass
获取当前的终端服务会话ID
如果活动会话ID和当前进程会话ID相同,则当前进程对应的用户在物理控制台上具有活动会话。 p>
如果你想知道的是当前进程运行的会话是否是活动的(但不一定在物理控制台上),你可以改用 WTSConnectState
选项 WTSQuerySessionInformation
。
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 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
.
这篇关于当多个用户登录Windows时,如何获取活动用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!