DirectorySearcher DirectorySearcher DirectorySearcher DirectorySearcher Class

定義

對 Active Directory 執行查詢。Performs queries against Active Directory Domain Services.

public ref class DirectorySearcher : System::ComponentModel::Component
[System.DirectoryServices.DSDescription("DirectorySearcherDesc")]
public class DirectorySearcher : System.ComponentModel.Component
type DirectorySearcher = class
    inherit Component
Public Class DirectorySearcher
Inherits Component
繼承
屬性

備註

DirectorySearcher使用物件,針對使用輕量型目錄存取協定(LDAP)的 Active Directory Domain Services 階層搜尋及執行查詢。Use a DirectorySearcher object to search and perform queries against an Active Directory Domain Services hierarchy using Lightweight Directory Access Protocol (LDAP). LDAP 是唯一支援目錄搜尋的系統提供 Active Directory 服務介面(ADSI)提供者。LDAP is the only system-supplied Active Directory Service Interfaces (ADSI) provider that supports directory searching. 系統管理員可以建立、改變和刪除階層中找到的物件。An administrator can make, alter, and delete objects that are found in the hierarchy. 如需詳細資訊,請參閱使用 microsoft.directoryservicesFor more information, see Using System.DirectoryServices.

當您建立的實例DirectorySearcher時,可以指定要抓取的根目錄,以及要抓取的選擇性屬性清單。When you create an instance of DirectorySearcher, you specify the root you want to retrieve, and an optional list of properties to retrieve. SearchRoot屬性可讓您設定其他屬性來執行下列工作:The SearchRoot property enables you to set additional properties to do the following tasks:

  • 在本機電腦上快取搜尋結果。Cache the search results on the local computer. 將屬性設定為true ,以將目錄資訊儲存在本機電腦上。 CacheResultsSet the CacheResults property to true to store directory information on the local computer. 只有在呼叫DirectoryEntry.CommitChanges方法時,才會對此本機快取進行更新並認可至 Active Directory Domain Services。Updates are made to this local cache and committed to Active Directory Domain Services only when the DirectoryEntry.CommitChanges method is called.

  • 使用ServerTimeLimit屬性指定要搜尋的時間長度。Specify the length of time to search, using the ServerTimeLimit property.

  • 僅取出屬性名稱。Retrieve attribute names only. 將屬性設定為true ,只取出已指派值的屬性名稱。 PropertyNamesOnlySet the PropertyNamesOnly property to true to retrieve only the names of attributes to which values have been assigned.

  • 執行分頁搜尋。Perform a paged search. PageSize設定屬性,以指定在分頁搜尋中傳回的物件數目上限。Set the PageSize property to specify the maximum number of objects that are returned in a paged search. 如果您不想要執行分頁搜尋,請將PageSize屬性設定為其預設值為零。If you do not want to perform a paged search, set the PageSize property to its default of zero.

  • 使用SizeLimit屬性,指定要傳回的最大專案數。Specify the maximum number of entries to return, using the SizeLimit property. 如果您將SizeLimit屬性的預設值設定為零,伺服器決定的預設值為1000個專案。If you set the SizeLimit property to its default of zero, the server-determined default is 1000 entries.

注意

如果傳回的專案數目上限和時間限制超過伺服器上所設定的限制,伺服器設定會覆寫元件設定。If the maximum number of returned entries and time limits exceed the limitations that are set on the server, the server settings override the component settings.

如需 DirectorySearcher 類別之執行個體的初始屬性值清單,請參閱 DirectorySearcher() 建構函式。For a list of initial property values for an instance of the DirectorySearcher class, see the DirectorySearcher() constructor.

注意

在使用這個類別之前,會假設您已對 Active Directory Domain Services 進行一般瞭解。It is assumed that you have a general understanding of Active Directory Domain Services before using this class. 如需詳細資訊,請System.DirectoryServices參閱總覽。For more information, see the System.DirectoryServices overview.

建構函式

DirectorySearcher() DirectorySearcher() DirectorySearcher() DirectorySearcher()

使用預設值,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with default values.

DirectorySearcher(DirectoryEntry) DirectorySearcher(DirectoryEntry) DirectorySearcher(DirectoryEntry) DirectorySearcher(DirectoryEntry)

使用指定的搜尋根目錄,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class using the specified search root.

DirectorySearcher(DirectoryEntry, String) DirectorySearcher(DirectoryEntry, String) DirectorySearcher(DirectoryEntry, String) DirectorySearcher(DirectoryEntry, String)

使用指定的搜尋根目錄和搜尋篩選條件,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search root and search filter.

DirectorySearcher(DirectoryEntry, String, String[]) DirectorySearcher(DirectoryEntry, String, String[]) DirectorySearcher(DirectoryEntry, String, String[]) DirectorySearcher(DirectoryEntry, String, String[])

使用所指定搜尋根目錄、搜尋篩選和要擷取的屬性,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search root, search filter, and properties to retrieve.

DirectorySearcher(DirectoryEntry, String, String[], SearchScope) DirectorySearcher(DirectoryEntry, String, String[], SearchScope) DirectorySearcher(DirectoryEntry, String, String[], SearchScope) DirectorySearcher(DirectoryEntry, String, String[], SearchScope)

使用指定的搜尋根目錄、搜尋篩選條件、要擷取的屬性和搜尋範圍,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search root, search filter, properties to retrieve, and search scope.

DirectorySearcher(String) DirectorySearcher(String) DirectorySearcher(String) DirectorySearcher(String)

使用指定的搜尋篩選條件,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search filter.

DirectorySearcher(String, String[]) DirectorySearcher(String, String[]) DirectorySearcher(String, String[]) DirectorySearcher(String, String[])

使用指定的搜尋篩選條件和要擷取的屬性,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search filter and properties to retrieve.

DirectorySearcher(String, String[], SearchScope) DirectorySearcher(String, String[], SearchScope) DirectorySearcher(String, String[], SearchScope) DirectorySearcher(String, String[], SearchScope)

使用指定的搜尋篩選條件、要擷取的屬性和搜尋範圍,初始化 DirectorySearcher 類別的新執行個體。Initializes a new instance of the DirectorySearcher class with the specified search filter, properties to retrieve, and search scope.

屬性

Asynchronous Asynchronous Asynchronous Asynchronous

取得或設定值,指出是否以非同步方式執行搜尋。Gets or sets a value that indicates if the search is performed asynchronously.

AttributeScopeQuery AttributeScopeQuery AttributeScopeQuery AttributeScopeQuery

取得或設定要搜尋之辨別名稱屬性的 LDAP 顯示名稱,Gets or sets the LDAP display name of the distinguished name attribute to search in. 只有一個屬性可用於這種類型的搜尋。Only one attribute can be used for this type of search.

CacheResults CacheResults CacheResults CacheResults

取得或設定值,指出是否在用戶端電腦上快取結果。Gets or sets a value indicating whether the result is cached on the client computer.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
ClientTimeout ClientTimeout ClientTimeout ClientTimeout

取得或設定用戶端等待伺服器傳回結果的最長時間。Gets or sets the maximum amount of time that the client waits for the server to return results. 如果在這個時間內伺服器沒有回應,則中止搜尋而且不會傳回任何結果。If the server does not respond within this time, the search is aborted and no results are returned.

Container Container Container Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DerefAlias DerefAlias DerefAlias DerefAlias

取得或設定值,指出如何解析搜尋期間找到之物件的別名。Gets or sets a value indicating how the aliases of objects that are found during a search should be resolved.

DesignMode DesignMode DesignMode DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
DirectorySynchronization DirectorySynchronization DirectorySynchronization DirectorySynchronization

取得或設定物件,表示與搜尋搭配使用的目錄同步處理控制項。Gets or sets an object that represents the directory synchronization control to use with the search.

Events Events Events Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ExtendedDN ExtendedDN ExtendedDN ExtendedDN

取得或設定值,表示辨別名稱的格式。Gets or sets a value that indicates the format of the distinguished names.

Filter Filter Filter Filter

取得或設定值,表示輕量型目錄存取協定 (LDAP) 格式的篩選條件字串。Gets or sets a value indicating the Lightweight Directory Access Protocol (LDAP) format filter string.

PageSize PageSize PageSize PageSize

取得或設定值,表示分頁搜尋中的頁面大小。Gets or sets a value indicating the page size in a paged search.

PropertiesToLoad PropertiesToLoad PropertiesToLoad PropertiesToLoad

取得值,表示搜尋期間要擷取的屬性清單。Gets a value indicating the list of properties to retrieve during the search.

PropertyNamesOnly PropertyNamesOnly PropertyNamesOnly PropertyNamesOnly

取得或設定值,指出搜尋是否只擷取已經指派值的屬性名稱。Gets or sets a value indicating whether the search retrieves only the names of attributes to which values have been assigned.

ReferralChasing ReferralChasing ReferralChasing ReferralChasing

取得或設定值,表示如何搜尋參考。Gets or sets a value indicating how referrals are chased.

SearchRoot SearchRoot SearchRoot SearchRoot

取得或設定值,表示 Active Directory 網域服務階層架構中搜尋開始處的節點。Gets or sets a value indicating the node in the Active Directory Domain Services hierarchy where the search starts.

SearchScope SearchScope SearchScope SearchScope

取得或設定值,表示伺服器觀察的搜尋範圍。Gets or sets a value indicating the scope of the search that is observed by the server.

SecurityMasks SecurityMasks SecurityMasks SecurityMasks

取得或設定值,表示搜尋應傳回指定屬性的哪些安全性存取資訊。Gets or sets a value indicating which security access information for the specified attributes should be returned by the search.

ServerPageTimeLimit ServerPageTimeLimit ServerPageTimeLimit ServerPageTimeLimit

取得或設定值,表示伺服器應搜尋個別結果頁的最長搜尋時間。Gets or sets a value indicating the maximum amount of time the server should search for an individual page of results. 這與整個搜尋的時間限制不同。This is not the same as the time limit for the entire search.

ServerTimeLimit ServerTimeLimit ServerTimeLimit ServerTimeLimit

ServerTimeLimit 屬性會取得或設定值,表示伺服器花費的最長搜尋時間。The ServerTimeLimit property gets or sets a value indicating the maximum amount of time the server spends searching. 如果達到時間限制,則只會傳回截至該時間點所找到的項目。If the time limit is reached, only entries that are found up to that point are returned.

Site Site Site Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
SizeLimit SizeLimit SizeLimit SizeLimit

取得或設定值,表示伺服器在搜尋中傳回的最多物件數目。Gets or sets a value indicating the maximum number of objects that the server returns in a search.

Sort Sort Sort Sort

取得或設定值,表示在其上排序結果的屬性。Gets or sets a value indicating the property on which the results are sorted.

Tombstone Tombstone Tombstone Tombstone

取得或設定值,指出搜尋是否還應傳回符合搜尋篩選條件的已刪除物件。Gets or sets a value indicating whether the search should also return deleted objects that match the search filter.

VirtualListView VirtualListView VirtualListView VirtualListView

取得或設定值,表示用於搜尋的虛擬清單檢視選項。Gets or sets a value indicating the virtual list view options for the search.

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 DirectorySearcher 物件所使用的 Managed 資源,並選擇性地釋放 Unmanaged 資源。Releases the managed resources that are used by the DirectorySearcher object and, optionally, releases unmanaged resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindAll() FindAll() FindAll() FindAll()

執行搜尋並傳回找到的項目集合。Executes the search and returns a collection of the entries that are found.

FindOne() FindOne() FindOne() FindOne()

執行搜尋並且只傳回找到的第一個項目。Executes the search and returns only the first entry that is found.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(Inherited from Component)

事件

Disposed Disposed Disposed Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

安全性

DirectoryServicesPermission
LinkDemand

適用於

另請參閱