Click to See Complete Forum and Search --> : Add users to Domain User Groups with ADSI
obijuan
February 28th, 2000, 05:27 PM
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
Lothar Haensler
February 29th, 2000, 01:28 AM
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
czimmerman
February 29th, 2000, 05:25 PM
See http://www.freevbcode.com/ShowCode.Asp?ID=796 for a generic function you can use for this.
Spotnick2
October 25th, 2000, 08:35 AM
If I check the article, this applies do MS Site Server, not Windows itself.
---
Nicolas LeBlanc
Product Manager
Ordiplan Inc.
Spotnick2
October 25th, 2000, 08:56 AM
It's not ADSI, but might work:
http://support.microsoft.com/support/kb/articles/Q159/4/98.ASP
---
Nicolas LeBlanc
Product Manager
Ordiplan Inc.
TCartwright
October 25th, 2000, 10:21 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.