Get UserPrincipalName

  • Thread starter Thread starter Dan
  • Start date Start date
D

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 !
 
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 !
 
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).
 
Back
Top