Get full name of user

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I don't know if its possible, but I would like to get the full name of the
user.

Using string name = System.Environment.UserName; only gives me the login
name of the user - however, when I push the windows start button (in XP) , my
full name is shown at the top of the start pop-up. Is it possible to query
for this full name value somewhere??


Best regards Jesper
 
Jesper,

You can probably find the user's full name in the Windows Registry. I would
suggest checking this on a machine that has multiple users and doing a
registry search until you find the correct path. Then you can use/modify the
code below to get the name in your application.

I hope this helps.

----------------------
string SubKey = string.Empty, Key = string.Empty, Username = string.Empty;

SubKey = @"Put your subkey here - e.g.\Software\Microsoft\etc";
Key = "Put your key here - e.g. username";

try
{
Microsoft.Win32.RegistryKey rkey = Microsoft.Win32.Registry.CurrentUser;
rkey = rkey.OpenSubKey(SubKey);
Username = rkey.GetValue(Key).ToString();
}
catch (Exception excep)
{
Debug.WriteLine(excep.ToString());
Username = string.Empty;
}
 
You can use windows directory services and get full name..

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\",
"/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://"
& DomainUser)
Dim FullName As String = ADEntry.Properties("FullName").Value


rajagopal
 
Back
Top