windows - Windows下如何查询用户的session id?

标签 windows winapi visual-c++ sessionid winlogon

假设有两个用户A和B登录了计算机,我们可以在cmd.exe中使用命令“query session”来获取每个用户名的所有 session id。

我的问题如下:

1、如何通过API(用户态或内核态)查询给定用户名的session id?

2、如何通过API(用户态或内核态)查询给定session id的用户名?

提前致谢!

最佳答案

您可以使用 Remote Desktop Services API为此。

1, How can I query the session id of a given user name through API (user mode or kernel mode)?

只需使用 WTSEnumerateSessions 获取所有 session ,遍历它们,用 WTSQuerySessionInformation 获取用户名并检查它是否匹配。

或者,如果您有 an access token对于该用户,您可以使用 GetTokenInformation为其检索 session ID。

2, How can I query the user name of a given session id through API (user mode or kernel mode)?

正如您可能从前面的答案中猜到的那样,您可以使用 WTSQuerySessionInformation从 session ID 中获取用户名。

关于windows - Windows下如何查询用户的session id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034666/

相关文章:

c++ - 如何为钩子(Hook)创建蹦床功能

windows - 将 CTreeCtrl 项目的复选框设置为部分状态

c++ - 缺少语法错误;前 *

c++ - OpenGL 项目返回 undefined reference

c++ - 如何在 Windows 中获取文件安全属性

c# - this.Region 路径数据导致一个小窗口

c++ - 异步过程调用

windows - 删除以相同起始字符开头的文件夹

visual-studio-2008 - boost::容器和错误: "C2679: binary ' =': no operator found"

c# - 如何将 vc++(例如:IListPtr)指针转换为 std::list?