Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Get Windows Username in WPF

Tags:

wpf

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 ?

like image 611
Ujjwal27 Avatar asked Apr 29 '13 07:04

Ujjwal27


People also ask

How do I find my username in C#?

GetCurrent(). Name; Returns: NetworkName\Username. Gets the user's Windows logon name.


2 Answers

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 
like image 139
Michel Keijzers Avatar answered Sep 26 '22 11:09

Michel Keijzers


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

You can get the name from this.

like image 21
Mehdi Bugnard Avatar answered Sep 25 '22 11:09

Mehdi Bugnard