Try this in .NET 3.5 or 4:
PrincipalContext infPC = new PrincipalContext(ContextType.Domain, "domain", "login", "password"); UserPrincipal infUP = new UserPrincipal(infPC); PrincipalSearcher infPS = new PrincipalSearcher(); UserPrincipal foundUP; GroupPrincipal infGP = new GroupPrincipal(infPC); GroupPrincipal foundGP; string CurrentUser = WindowsIdentity.GetCurrent().Name; infUP.SamAccountName = CurrentUser; infPS.QueryFilter = infUP; foundUP = infPS.FindOne(); infGP.Name = "CustomGroup"; infPS.QueryFilter = infGP; foundGP = infPS.FindOne(); bool ismember = foundUP.IsMemberOf(foundGP);
source share