2

I'm trying to figure out how to manage a local group with C#.

What happens now, is that I have a local group called "TestGroup". Within this local group, I have 3 local user and 1 domain members as follows:

  1. GV\member1
  2. member2
  3. member3
  4. member4

Where GV\member is domain user and rest is local user.

I have the following basic code:

Code:

using (PrincipalContext lpc = new PrincipalContext(ContextType.Machine))
{
    GroupPrincipal mainGroup = GroupPrincipal.FindByIdentity(lpc, "TestGroup");    
    PrincipalSearchResult<Principal> members = mainGroup.GetMembers();

    if (members != null)
    {
        foreach (Principal member in members)
        {
            // Display name
        }
    }
}

While executing this code, I encounter an error message saying "network path was not found". The funny part is, if my group only contains local users, it works perfectly.

Is there anything that I did wrong? I apologize if this question is silly in any way. It's probably something basic I guess.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Joehom Sum
  • 322
  • 1
  • 4
  • 13

0 Answers0