Platform SDK: Active Directory, ADSI, and Directory Services

IDirectorySearch::AbandonSearch

The IDirectorySearch::AbandonSearch method abandons a search that an earlier call to the ExecuteSearch method initiated.

HRESULT AbandonSearch(
  ADS_SEARCH_HANDLE hSearchHandle  
);

Parameters

[in] hSearchHandle
Provides a handle to the search context.

Return Values

This method returns the standard return values, including S_OK if the first row is obtained successfully.

For other return values, see ADSI Error Codes.

Remarks

IDirectorySearch::AbandonSearch may be used if the Page_Size or Asynchronous options can be specified through IDirectorySearch::SetSearchPreference before the search is executed.

Example Code [C++]

LPWSTR pszAttr[] = { L"ADsPath", L"Name", L"samAccountName" };
ADS_SEARCH_HANDLE hSearch;
DWORD dwCount= sizeof(pszAttr)/sizeof(LPWSTR);
////////////////////////////////////////////////////////////////////
//NOTE: Assume the Page Size has been set using SetSearchPreference
// For brevity, omit error handling.
////////////////////////////////////////////////////////////////////
 
// Search for all users with a last name that starts with h.
hr = m_pSearch->ExecuteSearch(L"(&(objectClass=user)(sn=h*))", pszAttr, dwCount, &hSearch );
while( m_pSearch->GetNextRow( hSearch) != S_ADS_NOMORE_ROWS )
{
    // Get the samAccountName
    hr = m_pSearch->GetColumn( hSearch, pszAttr[2], &col );
    if ( !SUCCEEDED(hr) )
    {
        hr = m_pSearch->AbandonSearch( hSearch );
        hr = m_pSearch->CloseSearchHandle(hSearch);
        m_pSearch->Release();
        break;
    }
   printf("%S\n", col.pADsValues->CaseIgnoreString); 
   m_pSearch->FreeColumn( &col );
}
 
m_pSearch->CloseSearchHandle( hSearch );

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

IDirectorySearch, IDirectorySearch::ExecuteSearch, IDirectorySearch::SetSearchPreference, ADSI Error Codes