开发者

How do I get the display name for an IdentityReference object?

开发者 https://www.devze.com 2023-03-27 02:56 出处:网络
Given the IdentityReference objects returned by开发者_运维技巧 WindowsIdentity.GetCurrent(), how do I find the display/friendly name of the given group?identityReference.Translate(typeof(NTAccount)).V

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

0

精彩评论

暂无评论...
验证码 换一张
取 消