locked
Give permission to another user on a Group using ActiveDirectorySecurity RRS feed

  • Question

  • User1850985877 posted

    Hi guys,

    I have to add a user in security tab(with read and write permission) for a selected GROUP using c# code. Please help me how to add the person in security tab using code.
    Thursday, December 6, 2012 1:00 AM

Answers

All replies

  • User-1166428634 posted

    first use :  using System.Security namespace

    second : write :  Roles.AddUserToRole("YOURUSERNAME","YOURROLE")

    Try it !!!

    Thursday, December 6, 2012 1:04 AM
  • User1850985877 posted

    Hi ,

     

    I donot want to add roles. I have to give user additional rights to manage Group in AD. I found the code for that, but dont know what name to add for "User_Name". Is it the dintinguished name or logon name.

    DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://path for Group");

    ActiveDirectorySecurity adSecurity = directoryEntry.ObjectSecurity;

    string sd = adSecurity.GetSecurityDescriptorSddlForm(AccessControlSections.All);

    IdentityReference newidentity = new System.Security.Principal.NTAccount("User_Name");

    ActiveDirectoryAccessRule newAccessRule = new ActiveDirectoryAccessRule(newidentity, ActiveDirectoryRights.WriteOwner, AccessControlType.Allow);

    directoryEntry.ObjectSecurity.AddAccessRule(newAccessRule);

    directoryEntry.CommitChanges();

    Thursday, December 6, 2012 2:00 AM
  • User1850985877 posted

    i'm getting access denied while using the above code.

    In UI i can add user and assign the permissions to that user. But using same credentials if i try the above code then its throwing error : ACCESS IS DENIED.

    Can anybody help me with that. :(

    Thursday, December 6, 2012 6:47 AM
  • User-166373564 posted

    Hi nix

    You could refer the case about assigning rights to the user group for particular OU in Active directory using C# below,

    http://social.msdn.microsoft.com/Forums/en/netfx64bit/thread/1283a2d0-0c76-442c-af4b-db255bca3215

    Moreover,  it's necessary for you to learn the usage of AddAccessRule method in ActiveDirectorySecurity Class,

    http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectorysecurity.aspx

    Kind regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2012 3:48 AM