Add User to a Group via VB.Net 1.1 Framework RRS feed

  • Question

  • User550531078 posted

    Wondering if anyone knows when you are trying to add a user to a group in an LDAP if there is a way to add the member into the uniquemember attribute instead of member attribute.  My VB.Net code to add a member to a group using System.DirectoryServices is below but it adds the member to the group using the member attribute.  We want to try and add user into the uniquemember attribute.  I am trying to use the System.DirectoryServices namespace in the .Net 1.1 Framework and using invoke command interoping over to ADSI to use the add command.  Using an iPlanet LDAP Server if it matters.  Anybody know any other way that can add a user via the uniquemember attribute?

    htLDAP = AppSettings.GetLDAPConnectionString

    mstrLDAPPwd = Me.GetLDAPPassword

    mstrLDAPName = htLDAP("LDAP")

    strLDAPOU = htLDAP("LDAPOU")

    strGroupOU = AppSettings.GetLDAPGroupOU

    Dim objRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & mstrLDAPName & "/" & strGroupOU)

    objRoot.Username = htLDAP("LDAPUserName")

    objRoot.Password = mstrLDAPPwd

    Dim objSearcher As DirectorySearcher = New DirectorySearcher(objRoot)

    objSearcher.Filter = "(cn=" & strGroupName & ")"

    Dim grpSearch As SearchResult = objSearcher.FindOne()

    Dim grp As DirectoryEntry = New DirectoryEntry(grpSearch.Path, htLDAP("LDAPUserName"), mstrLDAPPwd, AuthenticationTypes.Delegation)

    Dim objUser As New DirectoryEntry("LDAP://" & mstrLDAPName & "/uid=" & strUid & "," & strLDAPOU, htLDAP("LDAPUserName"), mstrLDAPPwd)

    Dim blnIsMember As Boolean = Convert.ToBoolean(grp.Invoke("IsMember", New Object() {objUser.Path}))

    If blnIsMember Then

    Return False


    grp.Invoke("Add", New Object() {objUser.Path})


    Return True

    End If

    Catch ex As Exception

    strError = ex.Message()

    Return False

    End Try

    Wednesday, September 20, 2006 2:59 PM

All replies

  • User1354132231 posted

    Simply add directly to the 'uniquemember' attribute then.  The syntax should be the DN (CN=User,OU=blah...) for most attributes like this.  Don't use the IADsGroup Add method.


    Wednesday, September 20, 2006 6:07 PM