2011-08-10 39 views

回答

22

identityReference.Translate(typeof(NTAccount)).Value应该这样做。

+0

完美,这是做的伎俩,我正在尝试'新NTAccount(identityReference.Value)':) –

+0

真棒:D,作品为群体以及用户 – nick

0

拉升组:

PrincipalContext PC = new PrincipalContext(ContextType.Machine); 

foreach (var G in WindowsIdentity.GetCurrent().Groups) 
{ 
string DisplayN = Principal.FindByIdentity (PC, IdentityType.Sid, G.ToString()).DisplayName; 
} 

拉升用户:

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

+1

这对于给定的组只能部分工作,它似乎不会返回活动目录中用户所属的所有组。我将'ContextType.Machine'改为'ContextType.Machine | ContextType.Domain'。 –