DirectoryEntries.Remove(DirectoryEntry) DirectoryEntries.Remove(DirectoryEntry) DirectoryEntries.Remove(DirectoryEntry) DirectoryEntries.Remove(DirectoryEntry) Method

Definition

Löscht einen Member dieser Auflistung.Deletes a member of this collection.

public:
 void Remove(System::DirectoryServices::DirectoryEntry ^ entry);
public void Remove (System.DirectoryServices.DirectoryEntry entry);
member this.Remove : System.DirectoryServices.DirectoryEntry -> unit
Public Sub Remove (entry As DirectoryEntry)

Parameter

entry
DirectoryEntry DirectoryEntry DirectoryEntry DirectoryEntry

Der Name des zu löschenden DirectoryEntry-Objekts.The name of the DirectoryEntry object to delete.

Ausnahmen

Während des Aufrufs der zugrunde liegenden Schnittstelle ist ein Fehler aufgetreten.An error occurred during the call to the underlying interface.

Beispiele

Im folgenden Visual Basic .NET-Beispiel wird ein DirectoryEntry neues-Objekt mit dem angegebenen Pfad erstellt. Anschließend wird ein neuer Eintrag im Container erstellt und gespeichert.The following Visual Basic .NET example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. Schließlich wird der neue Eintrag abgerufen und gelöscht.Finally, it retrieves the new entry and deletes it.

Imports System  
Imports System.DirectoryServices  

Class MyClass1  
   Shared Sub Main()  
      Try  
         Dim strPath As String = "IIS://localhost/W3SVC/1/Root"  
         Dim strName As String = ""  

         ' Create a new 'DirectoryEntry' object with the given path.  
         Dim myDE As New DirectoryEntry(strPath)  
         Dim myEntries As DirectoryEntries = myDE.Children  

         ' Create a new entry 'Sample' in the container.  
         Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("Sample", myDE.SchemaClassName)  
         ' Save changes of entry in the 'Active Directory Domain Services'.  
         myDirectoryEntry.CommitChanges()  
         Console.WriteLine(myDirectoryEntry.Name + " entry is created in container.")  

         ' Find 'Sample' entry in container.  
         myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName)  
         Console.WriteLine(myDirectoryEntry.Name + " found in container.")  
         ' Remove 'Sample' entry from container.  
         strName = myDirectoryEntry.Name  
         myEntries.Remove(myDirectoryEntry)  
         Console.WriteLine(strName + " entry is removed from container.")  

      Catch e As Exception  
         Console.WriteLine("The following exception was raised : {0}", e.Message.ToString())  
      End Try  
   End Sub 'Main  
End Class 'MyClass1  

Im folgenden C# Beispiel wird ein neues DirectoryEntry -Objekt mit dem angegebenen Pfad erstellt. Anschließend wird ein neuer Eintrag im Container erstellt und gespeichert.The following C# example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. Schließlich wird der neue Eintrag abgerufen und gelöscht.Finally, it retrieves the new entry and deletes it.

using System;  
using System.DirectoryServices;   

class MyClass1  
{  
   static void Main()  
   {  
      try  
      {  
         String strPath = "IIS://localhost/W3SVC/1/Root";  
         String strName = "";  

         // Create a new 'DirectoryEntry' object with the given path.  
         DirectoryEntry myDE = new DirectoryEntry(strPath);  
         DirectoryEntries myEntries = myDE.Children;  

         // Create a new entry 'Sample' in the container.  
         DirectoryEntry myDirectoryEntry =   
            myEntries.Add("Sample", myDE.SchemaClassName);  
         // Save changes of entry in the 'Active Directory Domain Services'.  
         myDirectoryEntry.CommitChanges();  
         Console.WriteLine (myDirectoryEntry.Name +   
            " entry is created in container.");  

         // Find 'Sample' entry in container.  
         myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName);  
         Console.WriteLine(myDirectoryEntry.Name + " found in container.");  
         // Remove 'Sample' entry from container.  
         strName = myDirectoryEntry.Name;  
         myEntries.Remove(myDirectoryEntry);  
         Console.WriteLine(strName+ " entry is removed from container.");  

      }  
      catch(Exception e)  
      {  
         Console.WriteLine("The following exception was raised : {0}",  
            e.Message);  
      }  
   }  
}  

Im folgenden C++ Beispiel wird ein neues DirectoryEntry -Objekt mit dem angegebenen Pfad erstellt. Anschließend wird ein neuer Eintrag im Container erstellt und gespeichert.The following C++ example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. Schließlich wird der neue Eintrag abgerufen und gelöscht.Finally, it retrieves the new entry and deletes it.

#using <mscorlib.dll>  
#using <System.dll>  
#using <System.Directoryservices.dll>  

using namespace System;  
using namespace System::DirectoryServices;   

int main() {  
    try {  
        String* strPath = S"IIS://localhost/W3SVC/1/Root";  
        String* strName = S"";  

        // Create a new 'DirectoryEntry' object with the given path.  
        DirectoryEntry* myDE = new DirectoryEntry(strPath);  
        DirectoryEntries* myEntries = myDE->Children;  

        // Create a new entry 'Sample' in the container.  
        DirectoryEntry* myDirectoryEntry =  myEntries->Add(S"Sample", myDE->SchemaClassName);  
        // Save changes of entry in the 'Active Directory Domain Services'.  
        myDirectoryEntry->CommitChanges();  
        Console::WriteLine(S"{0} entry is created in container.", myDirectoryEntry->Name);  

        // Find 'Sample' entry in container.  
        myDirectoryEntry = myEntries->Find(S"Sample", myDE->SchemaClassName);  
        Console::WriteLine(S"{0} found in container.", myDirectoryEntry->Name);  
        // Remove 'Sample' entry from container.  
        strName = myDirectoryEntry->Name;  
        myEntries->Remove(myDirectoryEntry);  
        Console::WriteLine(S"{0} entry is removed from container.", strName);  
    } catch(Exception* e) {  
        Console::WriteLine(S"The following exception was raised : {0}", e->Message);  
    }  
}  

Hinweise

Wenn es sich bei dem zu entfernenden Eintrag um einen Container handelt, muss der Container leer sein.If the entry to be removed is a container, the container must be empty. Um einen Container und alle untergeordneten Elemente zu löschen, DeleteTree verwenden Sie die-Methode.To delete a container and all its children, use the DeleteTree method.

Gilt für: