Compartir a través de


Deleting Directory Objects

To remove a directory object, the DirectoryEntries class provides the Remove method. This method removes a child entry from the Children collection of the current parent DirectoryEntry object. This method can only be used on empty container or on objects that are not used as containers for a directory tree, such as printers or computer nodes. For information about deleting a container that has child objects, see Deleting a Sub-Tree of Objects.

The following example shows how to remove an object from the directory.

Dim entry As New DirectoryServices.DirectoryEntry("WinNT://DomainName")
Dim entryToRemove As DirectoryServices.DirectoryEntry

' Add code here to set entryToRemove to the entry you want to remove.
entry.Children.Remove(entryToRemove)
System.DirectoryServices.DirectoryEntry entry = 
   new System.DirectoryServices.DirectoryEntry("WinNT://DomainName");
System.DirectoryServices.DirectoryEntry entryToRemove = null;

// Add code here to set entryToRemove to the entry you want to remove.
entry.Children.Remove(entryToRemove);

See Also

Reference

System.DirectoryServices
DirectoryEntry
DirectoryEntries

Concepts

Creating, Deleting, Renaming and Moving Objects
Deleting a Sub-Tree of Objects

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.