I have tried this link, but i am getting only the user id i want the complete name of the user
            Asked
            
        
        
            Active
            
        
            Viewed 971 times
        
    -4
            
            
        - 
                    Where are you expecting the user name to come from? Is it in the database, and are you retrieving it when the user logs in? – DOK Apr 29 '13 at 13:59
 - 
                    http://stackoverflow.com/questions/3175004/get-windows-user-name-different-methods – Maxim Apr 29 '13 at 14:02
 - 
                    i am trying to get it in my WPF application , the present logged in user name from windows machine(complete user name) – Ujjwal27 Apr 30 '13 at 05:06
 
1 Answers
0
            This will get you the full name of the user logged in on the computer
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;
}
        Toon Casteele
        
- 2,479
 - 15
 - 25