| Platform SDK: Active Directory, ADSI, and Directory Services | 
The IADsGroup::Add method adds an ADSI object to an existing group.
HRESULT IADsGroup::Add( BSTR bstrNewItem );
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 bstrNewItem parameter to add a security principal to a 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.Add("WinNT://S-1-5-21-35135249072896")
is equivalent to
Dim group As IADsGroup
group.Add("WinNT://Microsoft/jsmith")
Adding a member using its SID through the WinNT provider is a new feature in Windows 2000 and the DSCLIENT package.
The following Visual Basic code snippet illustrates how to add a user object ("jsmith") to the group ("Administrators") on the "Microsoft" domain, using the WinNT provider.
Dim grp As IADsGroup
Set grp = GetObject("WinNT://Microsoft/Administrators")
grp.Add ("WinNT://Microsoft/jsmith")
 
The following Visual Basic code snippet illustrates how to add a user object to a group using the LDAP provider.
Dim grp As IADsGroup
Set grp = GetObject("LDAP://CN=Administrators, CN=Users, DC=Microsoft, DC=com")
grp.Add("LDAP://CN=John Smith, OU=Sales,DC=Microsoft,DC=com")
The following C++/C code snippet adds an existing user account to the Administrators group.
IADsGroup *pGroup;
HRESULT hr;
LWPSTR adsPath = L"WinNT://Microsoft/Administrators";
hr = ADsGetObject(adsPath,IID_IADsGroup,(void**)&pGroup);
if(FAILED(hr)) exit(hr);
// assuming the "WinNT://Microsoft/jsmith" user account exists 
// and does not already belong to the Administrators group.
hr = pGroup->Add("WinNT://Microsoft/jsmith");
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