I am trying to "Delegate control" for Organizational Unit in Active Directory using c#
I am using the following code:
try
{
using (DirectoryEntry deOU = new DirectoryEntry("LDAP://MYDOMAIN/OU=MYOU", "admin_user_on_domain", "password"))
{
NTAccount acctUser = new NTAccount("some_user");
ActiveDirectoryAccessRule ruleReadWriteProp = new ActiveDirectoryAccessRule((IdentityReference)acctUser, ActiveDirectoryRights.GenericAll, AccessControlType.Allow);
deOU.ObjectSecurity.AddAccessRule(ruleReadWriteProp);
deOU.Options.SecurityMasks = SecurityMasks.Dacl;
deOU.CommitChanges();
Console.Write("DONE");
}
}
catch (Exception ex)
{
//Do something with exception
}
The scenario details:
- Windows server 2008 R2.
- project target (.net 2.0)
- I am running code from my machine connected to the server via LAN.
- Code is NOT asp.net code , it`s native c# code.
The code produces the following exception :
System.DirectoryServices.DirectoryServicesCOMException
Message: An operations error occurred.
I tried to run the code Directly on the server ,, the same exception appear , please advice thanks