I have tried using System.Environment.UserName
and My.User.Name
in VB.
But I get the result: ASIA/rz2kl1 (which is my username)
But I want (Doe, John) which is the name associated with username and comes on top of the start menu.
I have tried using System.Environment.UserName
and My.User.Name
in VB.
But I get the result: ASIA/rz2kl1 (which is my username)
But I want (Doe, John) which is the name associated with username and comes on top of the start menu.
Use GetUserNameEx
function.
Retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name.
If the thread is impersonating a client, GetUserNameEx returns the name of the client.
More documentation can be found here.
Something like this should be helpful:
Dim UserName As String = "ASIA\rz2kl1 (Doe, John)"
Dim ExtractName() As String = UserName.Split()
Dim Name As String = ExtractName(1) + " " + ExtractName(2)
Add the following reference
Add the following import:
Imports System.DirectoryServices.AccountManagement
Finally, add the following line of code:
Dim userFullName As String = UserPrincipal.Current.DisplayName