Share via


IADsCollection::Remove 方法 (iads.h)

IADsCollection::Remove方法會從這個 ADSI 集合物件中移除具名專案。

語法

HRESULT Remove(
  [in] BSTR bstrItemToBeRemoved
);

參數

[in] bstrItemToBeRemoved

以 Null 結尾的 Unicode 字串,指定 IADsCollection::Add所指定的專案名稱。

傳回值

這個方法支援標準傳回值,包括 S_OK。 如需詳細資訊和其他傳回值,請參閱 ADSI 錯誤碼

備註

目錄服務的集合也可以包含一組不可變的物件。

不需要直接移除專案的集合才能傳回 E_NOTIMPL

範例

下列 Visual Basic 程式碼範例示範如何從使用中檔案服務會話的集合中移除具名會話物件。

Dim fso As IADsFileServiceOperations 
Dim ses As IADsSession
Dim coll As IADsCollection
Dim mySessionName As String

On Error GoTo Cleanup

Set fso = GetObject("WinNT://myComputer/FabrikamServer") 
Set coll = fso.Sessions

' Insert code to set mySessionName to the name of the mySession 
' session object.
 
' The following statement invokes IADsCollection::Remove.
coll.Remove mySessionName

Cleanup:
    If (Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set fso = Nothing
    Set ses = Nothing
    Set coll = Nothing

下列 C++ 程式碼範例示範如何從使用中檔案服務會話的集合中移除具名會話物件。

HRESULT RemoveASessionObjectFromCollection()
{
    LPWSTR adspath = L"WinNT://myComputer/FabrikamServer";
    HRESULT hr = S_OK;
    IADsCollection *pColl = NULL;
    IADsFileServiceOperations *pFso = NULL;

    hr = ADsGetObject(adspath,IID_IADsFileServiceOperations,(void**)&pFso);
    if(FAILED(hr)) {goto Cleanup;}

    hr = pFso->Sessions(&pColl);
    if(FAILED(hr)) {goto Cleanup;}

    hr = pColl->Remove(CComBSTR("MySession"));

Cleanup
    if(pFso) pFso->Release();
    if(pColl) pColl->Release();

    return hr;
}

需求

   
最低支援的用戶端 Windows Vista
最低支援的伺服器 Windows Server 2008
目標平台 Windows
標頭 iads.h
Dll Activeds.dll

另請參閱

ADSI 錯誤碼

IADsCollection

IADsCollection::Add