0
Answer

Adding a Active Directory user to a local group.

Andre

Andre

18y
1.8k
1
Hi everyone,

I've searched alot of code samples of how to add Active Directory users to a local group.

I got now the following code:

GroupName = TestGroup
UserName = mod\u00p3n4

using DirectoryServices;

public void addUserToGroup(string GroupName, string UserName)
{
    DirectoryEntry _groupEntry;
    DirectoryEntry _group;
    DirectoryEntry _usr;

    try
    {
         _groupEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
         _group = _groupEntry.Children.Find(GroupName);
         _usr = _group.Children.Find(UserName)
         _group.CommitChanges();
    }
    catch(Exception ex)
    {
          MessageBox.Show(ex.Message);
    }
   
}