我怎样才能在Windows 7中使用WPF获得完整的用户名?
答
这将让你的用户的全名登录的计算机上的完整名称
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;
}
你在哪里期待用户名来自哪里?它是否在数据库中,并且在用户登录时检索它? – DOK 2013-04-29 13:59:57
http://stackoverflow.com/questions/3175004/get-windows-user-name-different-methods – Maxim 2013-04-29 14:02:33
我想让它在我的WPF应用程序中,当前从Windows机器登录的用户名(完整的用户名) – Ujjwal27 2013-04-30 05:06:26