如何获得IdentityReference对象的显示名称?
本文关键字:显示 何获得 IdentityReference 对象 | 更新日期: 2023-09-27 18:04:54
给定WindowsIdentity.GetCurrent()
返回的IdentityReference
对象,我如何找到给定组的显示/友好名称?
identityReference.Translate(typeof(NTAccount)).Value
应该这样做
try for 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;
见http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx