2011-08-10 5 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'. –

관련 문제