How do I get the logged on persons actual name? I already know how to get their logon name but I need their actual first and last name.
Thanks in advance.
Printable View
How do I get the logged on persons actual name? I already know how to get their logon name but I need their actual first and last name.
Thanks in advance.
I don't think that is available unless the user has entered it somewhere.
One good way is to ask them first what their name is then use that name.
Are you using Active Directory and Windows integrated authentication?Quote:
Originally Posted by 2MuchRiceMakesMeSick
Environment.Username
Quote:
Originally Posted by MasterBlaster
Im not sure. its windows XP sp2
that returns the USERNAME im looking for the Users actual nameQuote:
Originally Posted by mendhak
Thats what is written in the earlier posts, it will just return the Username. I don't think users full name is available anywhere.Quote:
Originally Posted by 2MuchRiceMakesMeSick
Only if it's stored in the ActiveDirectory can you get to the user's "actual name."
In your code, import System.DirectoryServices, instantiate a new DirectoryEntry object, passing it the LDAP path (it usually looks like LDAP://mydomain) and then create a DirectorySearcher which will filter... wait, let me write a code example, brb.
HTH :afrog:Code:DirectoryEntry de = new DirectoryEntry("LDAP://mydomain");
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "(&(objectClass=user)(l=" + Environment.UserName + "))";
foreach(SearchResult sr in ds.FindAll())
{
MessageBox.Show(sr.Properties["givenName"][0].ToString());
MessageBox.Show(sr.Properties["initials"][0].ToString());
MessageBox.Show(sr.Properties["ln"][0].ToString());
}
thank you very much!
No prob. Add Resolved to the thread title so that other people who have the same question in the future can do a search and completely overlook this post.