Given the IdentityReference
objects returned by开发者_运维技巧 WindowsIdentity.GetCurrent()
, how do I find the display/friendly name of the given group?
identityReference.Translate(typeof(NTAccount)).Value
should do it.
try for the Groups:
PrincipalContext PC = new PrincipalContext(ContextType.Machine);
foreach (var G in WindowsIdentity.GetCurrent().Groups )
{
string DisplayN = Principal.FindByIdentity (PC, IdentityType.Sid, G.ToString() ).DisplayName;
}
try for the User:
string DisplayN = Principal.FindByIdentity (new PrincipalContext(ContextType.Machine), IdentityType.Sid, WindowsIdentity.GetCurrent().User.ToString() ).DisplayName;
see http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx
精彩评论