charles

charles

  • NA
  • 13
  • 0

Adding AD Groups to local machine groups

Jul 2 2008 9:44 AM

Is there a way in C# to add a domain group to a local group on the machine? I need to add groups, not users. I have read a lot of articles about adding users, but nothing on adding groups. When I try to modify the code to use the group name, it has failed. Here is the code I am trying to use:

[code]

private void _addGroups()

{

try

{

DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");

DirectoryEntry NewUser = AD.Children.Add("Software Development Group", "user");

NewUser.CommitChanges();

DirectoryEntry grp;

grp = AD.Children.Find("Administrators", "group");

if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }

}

catch (Exception ex)

{

MessageBox.Show(ex.StackTrace, ex.Message);

}

}

[/code]


Answers (3)