Here's an example method using the System.DirectoryServices
namespace:
public bool BelongsToGroup(string computerName, string groupName, string domain)
{
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, domain);
ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(domainContext, computerName);
foreach (Principal result in computer.GetGroups())
{
if (result.Name == groupName)
{
return true;
}
}
return false;
}
So you could call it like this:
string computerName = Environment.MachineName;
string groupName = "Group Name";
string domainName = "Domain Name";
bool test = BelongsToGroup(computerName, groupName, domainName);