NT Groups in .NET 2.0

posted @ Saturday, September 10, 2005 12:43 PM

 

Yesterday, we needed to get the NT groups associated to an account. I have done this before, but now our team is working in .NET 2.0. It's worth noting that the value for each group returned from the WindowsIdentity is in the form of a SID, or a SecurityIdentifier which we can use to translate into a more human readable form, the NTAccount.

 

WindowsIdentity wi = WindowsIdentity.GetCurrent();
if
(wi != null)
{
foreach(IdentityReference group in wi.Groups)
{
if(group != null)
{
NTAccount acct
= group.Translate(typeof(NTAccount)) as NTAccount;
if
(acct != null)
{
Console.WriteLine(acct.Value)
;
}
}
}
}