Check if user is part of administrator group - C#
问题 I have code to verify if user is present in administrator group on local machine. The code works fine if user is directly present in administrator group using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group")) { foreach (object member in (IEnumerable)groupEntry.Invoke("Members")) { using (DirectoryEntry memberEntry = new DirectoryEntry(member)) { if (memberEntry.Name.ToLower() == UserName.ToLower()) { IsUserAdmin = true; break; } } } } But the code fails if