2011-08-10 14 views

答えて

22

identityReference.Translate(typeof(NTAccount)).Valueはそれを行う必要があります参照してください。

+0

パーフェクト、これはトリックでした、私は 'new 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'。 –

関連する問題