How do I get the display name of the user that is logged in? Not the username, but the display name, such as is shown in the screenshot below - and as seen on the start menu in any Windows Vista/7 computer.
I tried a bunch of different suggestions from other questions, but they all show the username, not the display name. You can see the results of these attempts in the above screenshot.
Imports System.Security.Principal Imports System.Threading Imports System.IO Imports System Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox("1: " & System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString & vbCrLf & _ "2: " & Environment.UserDomainName & vbCrLf & _ "3: " & WindowsIdentity.GetCurrent().Name & vbCrLf & _ "4: " & Thread.CurrentPrincipal.Identity.Name & vbCrLf & _ "5: " & Environment.UserName & vbCrLf & _ "6: " & My.User.Name & vbCrLf & "7: " & My.Computer.Name) End Sub End Class
In the box, type cmd and press Enter. The command prompt window will appear. Type whoami and press Enter. Your current user name will be displayed.
You can do this by clicking the Start button or pressing the Windows key, typing “Control Panel” into the search box in the Start menu, and then clicking on the Control Panel app. Next, click “User accounts.” Click “User accounts” one more time. Now, select “Change your account name” to change your display name.
You should use UserPrincipal.DisplayName
:
System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName
To do so, you'll need to and add a reference to System.DirectoryServices.AccountManagement.dll
from your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With