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:
- GV\member1
- member2
- member3
- 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.