Home All Groups Group Topic Archive Search About

Get UserPrincipalName

Author
6 Nov 2007 3:04 PM
Dan
Hi,

Is it possible to get the UserPrincipalName of a user from the
WindowsIdentity object ? I'm only able to get the sAMAccount from
WidowsIdentity.GetCurrent().Name.

Thank you !

Author
6 Nov 2007 5:36 PM
Vadym Stetsiak
Hello, Dan!

IMO UserPrincipalName is an Active Directory (AD) attribute. So, having
WindowsIdentity you're  to be able to query
for UserPrincipalName using DirectoryServices.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com


You wrote  on Tue, 06 Nov 2007 15:04:19 -0000:

D> Hi,

D> Is it possible to get the UserPrincipalName of a user from the
D> WindowsIdentity object ? I'm only able to get the sAMAccount from
D> WidowsIdentity.GetCurrent().Name.

D> Thank you !
Author
6 Nov 2007 7:44 PM
Larry Smith
> Is it possible to get the UserPrincipalName of a user from the
> WindowsIdentity object ? I'm only able to get the sAMAccount from
> WidowsIdentity.GetCurrent().Name.

Don't know if there's a .NET function for this but you can always P/Invoke
to "GetUserNameEx()" in the WinAPI. Note that the last time I did this
however (a few years back), you had to be running in a domain to retrieve
the name in any format other than "NameSamCompatible" and "NameDisplay" (see
the EXTENDED_NAME_FORMAT parameter for the latter function). Otherwise the
function would fail and "GetLastError()" would return ERROR_NONE_MAPPED (as
mentioned in this function).

AddThis Social Bookmark Button