次の方法で共有


DirectoryEntries.Find メソッド (String, String)

指定した名前で指定した型の子を返します。

Overloads Public Function Find( _
   ByVal name As String, _   ByVal schemaClassName As String _) As DirectoryEntry
[C#]
public DirectoryEntry Find(stringname,stringschemaClassName);
[C++]
public: DirectoryEntry* Find(String* name,String* schemaClassName);
[JScript]
public function Find(
   name : String,schemaClassName : String) : DirectoryEntry;

パラメータ

  • name
    検索する子の名前。
  • schemaClassName
    検索する子の型。

戻り値

見つかった子を表す DirectoryEntry

例外

例外の種類 条件
InvalidOperationException Active Directory オブジェクトがコンテナではありません。
COMException 基になるインターフェイスでエラーが発生しました。

使用例

[Visual Basic, C#, C++] 指定したパスを持つ新しい DirectoryEntry を作成し、そのコンテナ内に新しいエントリを作成し、それを保存する例を次に示します。この例は、新しく作成したエントリの取得を試みます。

 
Imports System
Imports System.DirectoryServices

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

         ' Create a 'DirectoryEntry' with the given path.
         Dim myDE As New DirectoryEntry(strPath)
         Dim myEntries As DirectoryEntries = myDE.Children
         
         ' Create a new entry in the container.
         myEntry1 = myEntries.Add("Sample Entry", myDE.SchemaClassName)
         ' Save changes in the 'Active Directory' store.
         myEntry1.CommitChanges()

         ' Find a child in the 'DirectoryEntries' with the 
         ' specified name and type.
         myEntry2 = myEntries.Find("Sample Entry", myDE.SchemaClassName)
         Console.WriteLine(myEntry2.Name + " is found in 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#] 
using System;
using System.DirectoryServices; 

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

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

         // Create a new entry in the container.
         myEntry1 = myEntries.Add("Sample Entry",myDE.SchemaClassName);
         // Save changes in the 'Active Directory' store.
         myEntry1.CommitChanges();

         // Find a child in the 'DirectoryEntries' with the 
         // specified name and type.
         myEntry2 = myEntries.Find("Sample Entry",myDE.SchemaClassName);
         Console.WriteLine (myEntry2.Name + " is found in container.");

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

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Directoryservices.dll>

using namespace System;
using namespace System::DirectoryServices; 

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

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

        // Create a new entry in the container.
        myEntry1 = myEntries->Add(S"Sample Entry", myDE->SchemaClassName);
        // Save changes in the 'Active Directory' store.
        myEntry1->CommitChanges();

        // Find a child in the 'DirectoryEntries' with the 
        // specified name and type.
        myEntry2 = myEntries->Find(S"Sample Entry", myDE->SchemaClassName);
        Console::WriteLine ("{0} is found in container.", myEntry2->Name);
    } catch(Exception* e) {
        Console::WriteLine("The following exception was raised : {0}", e->Message);
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

DirectoryEntries クラス | DirectoryEntries メンバ | System.DirectoryServices 名前空間 | DirectoryEntries.Find オーバーロードの一覧 | DirectoryEntry