43

I would like to display the Username in my WPF application, where it should get the username from the current user logged in?

so my question how can we get the username of windows logged in user from WPF App ?

2 Answers 2

64
System.Security.Principal.WindowsIdentity.GetCurrent().Name

I also found:

Environment.UserName

or

System.Windows.Forms.SystemInformation.UserName

I cannot try it so check for yourself the result.

Added: Full user name:

Imports System.DirectoryServices.AccountManagement

Dim userFullName As String = UserPrincipal.Current.DisplayName
3
  • 2
    System.Security.Principal.WindowsIdentity.GetCurrent().Name, This one is working Thank you
    – Ujjwal27
    Commented Apr 29, 2013 at 8:18
  • 1
    How can i get the Complete user name instead of Just User ID Example : instead of Displaying Ujjwal27 display "Ujjwal Vaddepati"
    – Ujjwal27
    Commented Apr 29, 2013 at 9:28
  • 1
    System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName is also useful - and necessary for providing the meaningful hint in ADAL. Commented Jan 10, 2014 at 20:53
12

Call WindowsIdentity.GetCurrent() to get the Windows user identity.

You can get the name from this.

Not the answer you're looking for? Browse other questions tagged or ask your own question.