Andre

Andre

  • NA
  • 11
  • 0

Adding a Active Directory user to a local group.

Oct 11 2006 7:43 AM
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);
    }
   
}