Platform SDK: Active Directory, ADSI, and Directory Services |
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 );
This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.
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.
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")
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();
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.
IADsMembers, IADsGroup, IADsGroup Property Methods, ADSI Error Codes