开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜