Share via


DirectoryEntries.Remove(DirectoryEntry) メソッド

定義

このコレクションのメンバーを削除します。

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)

パラメーター

entry
DirectoryEntry

削除する DirectoryEntry オブジェクトの名前。

例外

基になるインターフェイスへの呼び出し中にエラーが発生しました。

次の Visual Basic .NET の例では、指定したパスを持つ新しい DirectoryEntry オブジェクトを作成し、コンテナーに新しいエントリを作成して保存します。 最後に、新しいエントリを取得して削除します。

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  

次の C# の例では、指定したパスを持つ新しい DirectoryEntry オブジェクトを作成し、コンテナーに新しいエントリを作成して保存します。 最後に、新しいエントリを取得して削除します。

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);  
      }  
   }  
}  

次の C++ の例では、指定したパスを持つ新しい DirectoryEntry オブジェクトを作成し、コンテナーに新しいエントリを作成して保存します。 最後に、新しいエントリを取得して削除します。

#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);  
    }  
}  

注釈

削除するエントリがコンテナーの場合、コンテナーは空である必要があります。 コンテナーとそのすべての子を削除するには、 メソッドを DeleteTree 使用します。

適用対象