-4

我已经尝试过这个链接,但我只得到用户 ID 我想要用户的完整名称

WPF 中的用户名

4

1 回答 1

0

这将为您提供在计算机上登录的用户的全名

Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
// or, if you're in Asp.Net with windows authentication you can use:
// WindowsPrincipal principal = (WindowsPrincipal)User;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain))
{
    UserPrincipal up = UserPrincipal.FindByIdentity(pc, principal.Identity.Name);
    thisUsername = up.DisplayName;
    // or return up.GivenName + " " + up.Surname;
}
于 2013-04-29T14:00:29.110 回答