how to Get Windows Username in WPF

前端 未结 2 781
滥情空心
滥情空心 2021-02-06 22:35

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

相关标签:
2条回答
  • 2021-02-06 23:14

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

    You can get the name from this.

    0 讨论(0)
  • 2021-02-06 23:18
    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
    
    0 讨论(0)
提交回复
热议问题