IADsCollection::Remove 方法 (iads.h)

IADsCollection::Remove 方法从此 ADSI 集合对象中删除命名项。

语法

HRESULT Remove(
  [in] BSTR bstrItemToBeRemoved
);

parameters

[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