471,319 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Windows user name

With

System.Security.Principal.WindowsIdentity.GetCurre nt().Name

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

Thanks
Ferdinand
Jan 26 '06 #1
4 12781
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ferdinand Zaubzer" <fe***@gmx.at> wrote in message
news:O3*************@tk2msftngp13.phx.gbl...
With

System.Security.Principal.WindowsIdentity.GetCurre nt().Name

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

Thanks
Ferdinand

Jan 26 '06 #2

"Ferdinand Zaubzer" <fe***@gmx.at> wrote in message
news:O3*************@tk2msftngp13.phx.gbl...
| With
|
| System.Security.Principal.WindowsIdentity.GetCurre nt().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.
Jan 26 '06 #3
Willy Denoyette [MVP] wrote:
"Ferdinand Zaubzer" <fe***@gmx.at> wrote in message
news:O3*************@tk2msftngp13.phx.gbl...
| With
|
| System.Security.Principal.WindowsIdentity.GetCurre nt().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
Jan 27 '06 #4
No, you have to set a reference to the System.DirectoryServices assembly.

Willy.

"Ferdinand Zaubzer" <fe***@gmx.at> wrote in message
news:43**************@gmx.at...
| Willy Denoyette [MVP] wrote:
| > "Ferdinand Zaubzer" <fe***@gmx.at> wrote in message
| > news:O3*************@tk2msftngp13.phx.gbl...
| > | With
| > |
| > | System.Security.Principal.WindowsIdentity.GetCurre nt().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
Jan 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Bob Everland | last post: by
3 posts views Thread by Steven Fox | last post: by
5 posts views Thread by dm3281 | last post: by
4 posts views Thread by =?Utf-8?B?QXZhRGV2?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.