Add group to an computer object security tab AD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whippet
    New Member
    • Jul 2010
    • 2

    Add group to an computer object security tab AD

    Hi,
    When you create a computer account in Active Directory (manually), you can change "The following user or group can join this computer to a domain". When you do this, the user or group is added to the security tab.

    I would like to do this with c# (automatically) and I cannot find a solution.

    Thank you for your help
    Sorry! I'm not an english people.
    Attached Files
  • whippet
    New Member
    • Jul 2010
    • 2

    #2
    Hi,
    I receive this error message : Object reference not set an instance of an object.

    My code :

    DirectoryEntry computers = new DirectoryEntry( sLDAP + PCTarget, "Domain" + "\\" + "user", "Password", AuthenticationT ypes.Secure);
    computers.Optio ns.SecurityMask s = SecurityMasks.O wner | SecurityMasks.G roup | SecurityMasks.D acl | SecurityMasks.S acl;

    try
    {
    ActiveDirectory Security sdc = computers.Objec tSecurity;
    NTAccount Account = new NTAccount("Doma in\\MyGroupName ");
    SecurityIdentif ier Sid = (SecurityIdenti fier)Account.Tr anslate(typeof( SecurityIdentif ier));
    ActiveDirectory AccessRule rule = new ActiveDirectory AccessRule(Sid, ActiveDirectory Rights.Extended Right | ActiveDirectory Rights.GenericR ead,AccessContr olType.Allow);
    The message appears when the SetAccesRule is executed!!!
    sdc.SetAccessRu le(rule);
    computers.Commi tChanges();
    computers.Close ();
    computers.Dispo se();
    }
    catch (Exception ex)
    {
    MessageBox.Show (ex.Message.ToS tring());
    }

    Thank you

    Comment

    Working...