Материал из .Net Framework эксперт
Delete Object
using System;
using System.DirectoryServices;
class MainClass
{
public static void Main()
{
DirectoryEntry de = new DirectoryEntry(
"LDAP://192.168.1.100/ou=accounting, dc=ispnet1, dc=net",
"cn=Administrator, dc=ispnet1, dc=net", "password",
AuthenticationTypes.ServerBind);
DirectoryEntries children = de.Children;
try
{
DirectoryEntry t = children.Find("ou=auditing");
t.DeleteTree();
de.rumitChanges();
Console.WriteLine("deleted");
} catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
Deleting Objects
using System;
using System.DirectoryServices;
public class MainClass
{
public static int Main(string[] args)
{
DirectoryEntry MyObject = new DirectoryEntry();
MyObject.Path = "LDAP://HMSRevenge/OU=Users,DC=Test,DC=com";
DirectoryEntries users = MyObject.Children;
foreach(DirectoryEntry D in users)
{
if(D.Properties["email"].Value.ToString() == "tom")
{
users.Remove(D);
}
}
MyObject.rumitChanges();
return 0;
}
}
Remove Object
using System;
using System.DirectoryServices;
class MainClass
{
public static void Main()
{
DirectoryEntry de = new DirectoryEntry(
"LDAP://192.168.1.100/ou=accounting, dc=ispnet1, dc=net",
"cn=Administrator, dc=ispnet1, dc=net", "password",
AuthenticationTypes.ServerBind);
DirectoryEntries children = de.Children;
try
{
DirectoryEntry t = children.Find("ou=auditing");
children.Remove(t);
de.rumitChanges();
Console.WriteLine("removed");
} catch (Exception)
{
Console.WriteLine("the object was not found");
}
}
}