windows 从登录 ID (LUID) (C++) 获取 UserToken

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4534031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:51:20  来源:igfitidea点击:

Get UserToken from Logon ID (LUID) (C++)

windowssessionsessionidterminal-services

提问by TCS

I'm trying to understand better how Windows sessions work, so if I have some weird mistakes in the question, please, let me know.

我试图更好地了解 Windows 会话的工作方式,所以如果我在问题中有一些奇怪的错误,请告诉我。

I use LsaEnumerateLogonSessions()to get all the logged on sessions in the system. Now I have LUID that represents a log-on, and if I understand correctly, it represents a user that logged on or a build it user like SYSTEM.

LsaEnumerateLogonSessions()用来获取系统中所有登录的会话。现在我有代表登录的 LUID,如果我理解正确,它代表登录的用户或像 SYSTEM 这样的构建用户。

Now, if user X starts a process, Windows gives that process a token that represents X.

现在,如果用户 X 启动一个进程,Windows 会为该进程提供一个代表 X 的令牌。

Is there a way (in a Windows service) to get the user's token from LUID? I know I can get it from a process HANDLE, but that is not what I want.

有没有办法(在 Windows 服务中)从 LUID 获取用户的令牌?我知道我可以从进程句柄中得到它,但这不是我想要的。

回答by kichik

You can use LsaGetLogonSessionDatato get the session id and then use WTSQueryUserTokento get the token from that. Note that you may need to run as LocalSystem for WTSQueryUserToken(see "How can I get the current user token for the physical session?" regarding that).

您可以使用LsaGetLogonSessionData来获取会话 ID,然后使用它WTSQueryUserToken来获取令牌。请注意,您可能需要作为 LocalSystem 运行WTSQueryUserToken(请参阅“我如何获取物理会话的当前用户令牌?”)。