Windows user name

  • Thread starter Thread starter Ferdinand Zaubzer
  • Start date Start date
F

Ferdinand Zaubzer

With

System.Security.Principal.WindowsIdentity.GetCurrent().Name

I get the user name of the current Windows user.
But how can I get the full name?

Thanks
Ferdinand
 
Ferdinand,

In order to do this, you would have to call the GetUserNameEx API
function through P/Invoke, passing the value of NameDisplay for the
NameFormat parameter.

Hope this helps.
 
| With
|
| System.Security.Principal.WindowsIdentity.GetCurrent().Name
|
| I get the user name of the current Windows user.
| But how can I get the full name?
|
| Thanks
| Ferdinand

Using the System.DirectoryServices namespace classes:

....
// get fullname of 'username' on 'servername'
using (DirectoryEntry domain = new
DirectoryEntry("WinNT://servername/username"))
{
string fullName = domain.Properties["FullName"].Value;
}

Willy.
 
Willy said:
| With
|
| System.Security.Principal.WindowsIdentity.GetCurrent().Name
|
| I get the user name of the current Windows user.
| But how can I get the full name?
|
| Thanks
| Ferdinand

Using the System.DirectoryServices namespace classes:

...
// get fullname of 'username' on 'servername'
using (DirectoryEntry domain = new
DirectoryEntry("WinNT://servername/username"))
{
string fullName = domain.Properties["FullName"].Value;
}

Thanks for the Hint!
But I don't have this System.DirectoryServices namespace.
Do I have to install any extensions?

Thanks
Ferdinand
 
No, you have to set a reference to the System.DirectoryServices assembly.

Willy.

| Willy Denoyette [MVP] wrote:
| > | > | With
| > |
| > | System.Security.Principal.WindowsIdentity.GetCurrent().Name
| > |
| > | I get the user name of the current Windows user.
| > | But how can I get the full name?
| > |
| > | Thanks
| > | Ferdinand
| >
| > Using the System.DirectoryServices namespace classes:
| >
| > ...
| > // get fullname of 'username' on 'servername'
| > using (DirectoryEntry domain = new
| > DirectoryEntry("WinNT://servername/username"))
| > {
| > string fullName = domain.Properties["FullName"].Value;
| > }
|
| Thanks for the Hint!
| But I don't have this System.DirectoryServices namespace.
| Do I have to install any extensions?
|
| Thanks
| Ferdinand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top