0

在我之前的问题的上下文中,我试图在 C++ 中获取当前登录的 Windows Active 目录用户的 UPN。我知道如何获取登录用户的 SID,但无法获取登录用户的 UPN。

4

1 回答 1

0

Assuming you are working as a server (with high privileges) against a client program, you can impersonate the user using the Windows impersonation API, then call GetUserNameExW with NameUserPrincipal as the name format. The tricky part here might be the impersonation, depending on what you have to work with.

If you only have the SID and impersonation is not an option, you can use WMI or LDAP and query the DC: search for the user entity with the matching SID and get the UserPrincipalName attribute. Again, you'll need sufficient permissions for this.

于 2014-06-17T13:42:35.970 回答