CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2000
    Location
    Florida
    Posts
    9

    Add users to Domain User Groups with ADSI

    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

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Add users to Domain User Groups with ADSI

    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








  3. #3

    Re: Add users to Domain User Groups with ADSI

    See http://www.freevbcode.com/ShowCode.Asp?ID=796 for a generic function you can use for this.


  4. #4
    Join Date
    Jul 1999
    Location
    Montreal, Quebec, Canada
    Posts
    192

    Re: Add users to Domain User Groups with ADSI

    If I check the article, this applies do MS Site Server, not Windows itself.

    ---
    Nicolas LeBlanc
    Product Manager
    Ordiplan Inc.

  5. #5
    Join Date
    Jul 1999
    Location
    Montreal, Quebec, Canada
    Posts
    192

    Re: Add users to Domain User Groups with ADSI

    It's not ADSI, but might work:

    http://support.microsoft.com/support.../Q159/4/98.ASP



    ---
    Nicolas LeBlanc
    Product Manager
    Ordiplan Inc.

  6. #6
    Join Date
    Apr 2000
    Location
    Houston, TX, USA
    Posts
    199

    Re: Add users to Domain User Groups with ADSI

    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.
    Tim C.
    //Will write code for food

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured