共用方式為


HOW TO:存取結構描述

下列類別可搭配 Active Directory 網域服務結構描述使用。

GetCurrentSchema 靜態方法可用來取得 ActiveDirectorySchema 物件,此物件代表目前登入之使用者為其成員的樹系的結構描述。

下列範例示範如何搭配 System.DirectoryServices.ActiveDirectory 命名空間來使用 Active Directory 網域服務結構描述。

列舉結構描述類別

下列 C# 範例示範如何列舉指定的結構描述中的所有類別。

using System.DirectoryServices.ActiveDirectory;

static void EnumSchemaClasses(ActiveDirectorySchema schema)
{
    foreach (ActiveDirectorySchemaClass schemaClass in 
        schema.FindAllClasses())
    {
        Console.WriteLine(schemaClass.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中的所有類別。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumSchemaClasses(ByVal schema As ActiveDirectorySchema)
    Dim schemaClass As ActiveDirectorySchemaClass
    For Each schemaClass In schema.FindAllClasses()
        Console.WriteLine(schemaClass.Name)
    Next schemaClass
End Sub 'EnumSchemaClasses

下列 C# 範例示範如何列舉指定的結構描述中指定類型的所有類別。

using System.DirectoryServices.ActiveDirectory;

static void EnumSchemaClasses(ActiveDirectorySchema schema, 
    SchemaClassType classType)
{
    foreach (ActiveDirectorySchemaClass schemaClass in 
        schema.FindAllClasses(classType))
    {
        Console.WriteLine(schemaClass.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中指定類型的所有類別。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumSchemaClasses(ByVal schema As ActiveDirectorySchema, _
ByVal classType As SchemaClassType)
    Dim schemaClass As ActiveDirectorySchemaClass
    For Each schemaClass In schema.FindAllClasses(classType)
        Console.WriteLine(schemaClass.Name)
    Next schemaClass
End Sub 'EnumSchemaClasses

下列 C# 範例示範如何列舉指定的結構描述中的所有無用類別。

using System.DirectoryServices.ActiveDirectory;

static void EnumDefunctSchemaClasses(ActiveDirectorySchema schema)
{
    foreach (ActiveDirectorySchemaClass schemaClass in
        schema.FindAllDefunctClasses())
    {
        Console.WriteLine(schemaClass.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中的所有無用類別。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumDefunctSchemaClasses(ByVal schema As ActiveDirectorySchema)
    Dim schemaClass As ActiveDirectorySchemaClass
    For Each schemaClass In schema.FindAllDefunctClasses()
         Console.WriteLine(schemaClass.Name)
    Next schemaClass
End Sub 'EnumDefunctSchemaClasses

列舉結構描述屬性

下列 C# 範例示範如何列舉指定的結構描述中的所有屬性。

using System.DirectoryServices.ActiveDirectory;

static void EnumSchemaProperties(ActiveDirectorySchema schema)
{
    foreach (ActiveDirectorySchemaProperty schemaProperty in 
        schema.FindAllProperties())
    {
        Console.WriteLine(schemaProperty.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中的所有屬性。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumSchemaProperties(ByVal schema As ActiveDirectorySchema)
    Dim schemaProperty As ActiveDirectorySchemaProperty
    For Each schemaProperty In schema.FindAllProperties()
        Console.WriteLine(schemaProperty.Name)
    Next schemaProperty
End Sub 'EnumSchemaProperties

下列 C# 範例示範如何列舉指定的結構描述中指定類型的所有屬性。

using System.DirectoryServices.ActiveDirectory;

static void EnumSchemaProperties(ActiveDirectorySchema schema, 
    PropertyTypes propertyType)
{
    foreach (ActiveDirectorySchemaProperty schemaProperty in 
        schema.FindAllProperties(propertyType))
    {
        Console.WriteLine(schemaProperty.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中指定類型的所有屬性。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumSchemaProperties(ByVal schema As ActiveDirectorySchema, _
ByVal propertyType As PropertyTypes)
    Dim schemaProperty As ActiveDirectorySchemaProperty
    For Each schemaProperty In schema.FindAllProperties(propertyType)
        Console.WriteLine(schemaProperty.Name)
    Next schemaProperty
End Sub 'EnumSchemaProperties

下列 C# 範例示範如何列舉指定的結構描述中的所有無用屬性。

using System.DirectoryServices.ActiveDirectory;

static void EnumDefunctSchemaProperties(ActiveDirectorySchema schema)
{
    foreach (ActiveDirectorySchemaProperty schemaProperty in
        schema.FindAllDefunctProperties())
    {
        Console.WriteLine(schemaProperty.Name);
    }
}

下列 Visual Basic .NET 範例示範如何列舉指定的結構描述中的所有無用屬性。

Imports System.DirectoryServices.ActiveDirectory

Sub EnumDefunctSchemaProperties(ByVal schema As ActiveDirectorySchema)
    Dim schemaProperty As ActiveDirectorySchemaProperty
    For Each schemaProperty In schema.FindAllDefunctProperties()
        Console.WriteLine(schemaProperty.Name)
    Next schemaProperty
End Sub 'EnumDefunctSchemaProperties

Send comments about this topic to Microsoft.

Copyright © 2008 by Microsoft Corporation.All rights reserved.