EDN Admin
Well-known member
Hello,
I am trying to clean from C# console application, children of a given object in Active Directory
The source code is below
<pre> public static void cleanChilds(String server,String objectDN,String user, String password)
{
DateTime now = DateTime.Now;
DirectoryEntry Ldap = null;
try
{
String entryDN = "LDAP://" + server + "/" + objectDN;
Console.WriteLine("[" + now.ToString() + "] Nettoyage des fils en vue dune supression, entrÃe: " + entryDN);
// CrÃer la connexion
Ldap = new DirectoryEntry(entryDN, user, password);
DirectorySearcher searcher = new DirectorySearcher(Ldap);
// RÃcuperer les fils pour faire le nettoyage
IEnumerator EmpEnumerator = Ldap.Children.GetEnumerator();
EmpEnumerator.Reset();
// Faire le nettoyage et logger
while (EmpEnumerator.MoveNext())
{
DirectoryEntry dirEntry = ((DirectoryEntry)EmpEnumerator.Current);
dirEntry.DeleteTree();
Console.WriteLine("[" + now.ToString() + "] Fils nettoyÃ: " + dirEntry.Properties["distinguishedName"].Value);
}
}
// En cas derreurs
catch (Exception Ex)
{
Console.WriteLine("[" + now.ToString() + "] Erreur lors du nettoyage: " + Ex.Message + Ex.StackTrace);
}
}[/code]
<br/>
I am using a console application, and the account used for deletion has the required permissions, I am sure of that beacause from an LDAP browser using this account it works, and by logging on the target machine with this account by manual deletion it works
as well
But running from application console I get the following error
<pre>Access is denied. (Exception fro
m HRESULT: 0x80070005 (E_ACCESSDENIED)) at System.DirectoryServices.Interop.Un
safeNativeMethods.IAdsDeleteOps.DeleteObject(Int32 flags)
at System.DirectoryServices.DirectoryEntry.DeleteTree()
at ConsoleApplication1.Program.cleanChilds(String server, String objectDN, St
ring user, String password) in C:UsersvphoDesktopTestConsoleApplication1Co
nsoleApplication1Program.cs:line 26[/code]
<br/>
So is there any setting to do ? I saw this problem is common on Sharepoint and ASP, no one has yet encoutred this from C shap
If its not the place for this message plase tell me the best location in technet to have an answer
Thanks in advance
View the full article
I am trying to clean from C# console application, children of a given object in Active Directory
The source code is below
<pre> public static void cleanChilds(String server,String objectDN,String user, String password)
{
DateTime now = DateTime.Now;
DirectoryEntry Ldap = null;
try
{
String entryDN = "LDAP://" + server + "/" + objectDN;
Console.WriteLine("[" + now.ToString() + "] Nettoyage des fils en vue dune supression, entrÃe: " + entryDN);
// CrÃer la connexion
Ldap = new DirectoryEntry(entryDN, user, password);
DirectorySearcher searcher = new DirectorySearcher(Ldap);
// RÃcuperer les fils pour faire le nettoyage
IEnumerator EmpEnumerator = Ldap.Children.GetEnumerator();
EmpEnumerator.Reset();
// Faire le nettoyage et logger
while (EmpEnumerator.MoveNext())
{
DirectoryEntry dirEntry = ((DirectoryEntry)EmpEnumerator.Current);
dirEntry.DeleteTree();
Console.WriteLine("[" + now.ToString() + "] Fils nettoyÃ: " + dirEntry.Properties["distinguishedName"].Value);
}
}
// En cas derreurs
catch (Exception Ex)
{
Console.WriteLine("[" + now.ToString() + "] Erreur lors du nettoyage: " + Ex.Message + Ex.StackTrace);
}
}[/code]
<br/>
I am using a console application, and the account used for deletion has the required permissions, I am sure of that beacause from an LDAP browser using this account it works, and by logging on the target machine with this account by manual deletion it works
as well
But running from application console I get the following error
<pre>Access is denied. (Exception fro
m HRESULT: 0x80070005 (E_ACCESSDENIED)) at System.DirectoryServices.Interop.Un
safeNativeMethods.IAdsDeleteOps.DeleteObject(Int32 flags)
at System.DirectoryServices.DirectoryEntry.DeleteTree()
at ConsoleApplication1.Program.cleanChilds(String server, String objectDN, St
ring user, String password) in C:UsersvphoDesktopTestConsoleApplication1Co
nsoleApplication1Program.cs:line 26[/code]
<br/>
So is there any setting to do ? I saw this problem is common on Sharepoint and ASP, no one has yet encoutred this from C shap
If its not the place for this message plase tell me the best location in technet to have an answer
Thanks in advance
View the full article