Platform SDK: Active Directory, ADSI, and Directory Services

IADsGroup::Remove

The IADsGroup::Remove method removes the specified user object from this group. The operation does not remove the group object itself even when there is no member left in the group.

HRESULT IADsGroup::Remove(
  BSTR bstrItemToBeRemoved  
);

Parameters

bstrItemToBeRemoved
[in] ADsPath of the object to be removed from the group.

Return Values

This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.

Remarks

You can use a SID in the ADsPath to remove a security principal from the group through the WinNT provider. For example, suppose the SID of a user, "Microsoft\jsmith", is S-1-5-21-35135249072896, the following statement

Dim group As IADsGroup
group.Remove("WinNT://S-1-5-21-35135249072896")

is equivalent to

Dim group As IADsGroup
group.Remove("WinNT://Microsoft/jsmith")

Removing a member using its SID through the WinNT provider is a new feature in Windows 2000 and the DSCLIENT package.

Example Code [Visual Basic]

The following is a Visual Basic code snippet that removes a user account from a group.

Dim grp As IADsGroup
Set grp = GetObject("WinNT://Microsoft/Administrators")
grp.Remove ("WinNT://Microsoft/jsmith")

Example Code [C++]

The following C++ code snippet removes a user from a group.

IADsGroup *pGroup;
HRESULT hr;
LPWSTR usrPath = L"WinNT://Microsoft/jsmith";
LPWSTR grpPath = L"WinNT://Microsoft/Administrators";

hr = ADsGetObject(grpPath, IID_IADsGroup, (void**)&pGroup);
if(FAILED(hr)) exit(hr);

hr = pGroup->Remove(usrPath);
if(FAILED(hr)) exit(hr);

pGroup->Release();

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

IADsMembers, IADsGroup, IADsGroup Property Methods, ADSI Error Codes