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]

Guest UserRank #1,422 · 1.2K reputationPosted Jul 2, 2008, 7:06 AM EDT
charles13 reputationPosted Jul 2, 2008, 11:40 AM EDT
Guest UserRank #1,422 · 1.2K reputationPosted Jul 2, 2008, 12:05 PM EDT
According to the API docs, you can add individual users or groups to other groups. I don't know if you can add a domain group to a local group with it, though.