What is the best way to retrieve a list of groups a user belongs to from a windows service?

```
List<string> groups = new List<string>();

foreach (IdentityReference ir in new WindowsIdentity(name).Groups)
{
     SecurityIdentifier sid = new SecurityIdentifier(ir.Value);
     NTAccount ntAccount = (NTAccount)sid.Translate(typeof(NTAccount));
     groups.Add(ntAccount.ToString());
}

```

I tried to use above code but it raised the following error.

```
Error communicating with client: System.Security.SecurityException: Incorrect function.

```