2011-08-10 37 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'。 –