Does anyone know how to add users to usergroups using ADSI? I haveevery other piece of information but the right commands to add this user. Thanks,
Juan Torres
Blue Cross Blue Shield of Florida
Configuration Management & Distribution Solutions
Printable View
Does anyone know how to add users to usergroups using ADSI? I haveevery other piece of information but the right commands to add this user. Thanks,
Juan Torres
Blue Cross Blue Shield of Florida
Configuration Management & Distribution Solutions
msdn article Q192782 has it for your:
Dim adsMemberOf
Dim adsGroup
Dim strLdapSrv
Dim strMemberPath, strUserCn, strUserDn, _
strGroupDn, strAdmin, strAdminPwd
strLdapSrv = "LDAP://localhost:5292"
strMemberPath = ",ou=Members,o=Microsoft"
strUserCn = "cn=JohnDoe"
strUserDn = strUserCn + strMemberPath
strGroupDn = strLdapSrv +
"/o=Microsoft/ou=Groups/cn=public"
strAdmin = "cn=Administrator,ou=Members,o=Microsoft"
strAdminPwd = "password"
'Bind to the specific group using Administrator credentials
set adsGroup = GetObject("LDAP:")
set adsGroup = adsGroup.OpenDSObject(strGroupDn, strAdmin, _
strAdminPwd, CLng(0))
'Create the new 'memberOf' object that will be stored in the
group
set adsMemberOf = adsGroup.Create("memberof", strUserCn)
'Add the path to the user and store it in the 'memberObject'
property
adsMemberOf.Put "memberobject", CStr(strUserDn)
'Flush the property cache and update the directory
adsMemberOf.SetInfo
'Destroy the objects
set adsMemberOf = nothing
set adsGroup = nothing
See http://www.freevbcode.com/ShowCode.Asp?ID=796 for a generic function you can use for this.
If I check the article, this applies do MS Site Server, not Windows itself.
---
Nicolas LeBlanc
Product Manager
Ordiplan Inc.
It's not ADSI, but might work:
http://support.microsoft.com/support.../Q159/4/98.ASP
---
Nicolas LeBlanc
Product Manager
Ordiplan Inc.
To use this, you must reference ADSI 2.5 library or higher, and the ADSI 2.5 must be installed on target server, adn the machine running this code.
public Function AddUserToGroup(strUserName as string, _
strGroup as string, _
optional strDomain as string) as Boolean
on error GoTo AddUserToGroup_Error
'********************************************************
'** Created By : tcartwright
'** Purpose :
'**
'**
'** Creation date : 4/12/99
'********************************************************
Dim GroupObj as IADsGroup ' Base group to add user to
Dim strUserPath as string
strDomain = FormatDomain(strDomain)
set GroupObj = GetObject(Domain & "/" & strGroup)
strUserPath = Domain & "/" & strUserName
GroupObj.Add (strUserPath) ' add the user to the group
AddUserToGroup = true
AddUserToGroup_Exit:
set GroupObj = nothing
Exit Function
AddUserToGroup_Error:
Err.Raise Err.Number
resume AddUserToGroup_Exit
End Function
private Function FormatDomain(strDomain as string) as string
If Right(strDomain, 1) = "/" then
strDomain = Left(strDomain, len(strDomain) - 1)
End If
If InStr(UCase(strDomain), UCase("WinNT://")) = 0 then
strDomain = "WinNT://" & strDomain
End If
If strDomain <> "" And strDomain <> Domain then
Domain = strDomain
End If
FormatDomain = strDomain
End Function
Tim Cartwright 'Will write code for food.
Sr Systems Architect - Information Systems
Splitrock Services Inc.