Results 1 to 7 of 7

Thread: [RESOLVED] Active Directory

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    172

    Resolved [RESOLVED] Active Directory

    Hi, is it possible to connect to the Active Directory without using a login and password?

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Active Directory

    seems you are working on app related to Active directory,may be you can look into this sample application.

    http://www.codeproject.com/KB/system...edirquery.aspx
    Last edited by riteshjain1982; May 27th, 2008 at 08:59 AM.
    __________________
    Rate the posts that helped you

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    172

    Re: Active Directory

    I need to know, for a specific user, in which group he's in.

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Active Directory

    have you tried with PropertiesToLoad.Add("memberOf") property of DirectorySearcher object
    __________________
    Rate the posts that helped you

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    172

    Re: Active Directory

    How do I get the IP of the LDAP?

  6. #6
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Active Directory

    I found one sample,this will work if user and machine on which you are running you app is in same domain.
    Code:
     Public Sub GetUserGroups(ByVal UserName As String)
    
            Dim search As New DirectorySearcher("")
            Dim intG_Counter As Int 
            Dim intcounter As Int 
            Dim strGroupName As String
            Dim strPrimaryGroup As String
            Dim GroupArr As Array
            Dim DataToWriteGroups As String
            Try
    
                search.Filter = "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(objectCategory=user)(samaccountname=" + UserName.ToString.Trim + "))"
                search.PropertiesToLoad.Add("memberOf")
    
                Dim result As SearchResult = search.FindOne()
    
                If Not (IsNothing(result)) Then
    
                    Try
                        intG_Counter = result.Properties("memberOf").Count
                    Catch exc As NullReferenceException
                        intG_Counter = 0
                    End Try
    
                    If intG_Counter > 0 Then
                        DataToWriteGroups = "Group(s) Belongs To User - " + UserName + ""
                         For intcounter = 0 To intG_Counter - 1
                            strGroupName = ""
                            strGroupName = CStr(result.Properties("memberOf")(intcounter))
                            GroupArr = Split(strGroupName, ",")
                            If Not (IsNothing(GroupArr(0))) Then
                                strGroupName = Mid(GroupArr(0), 4, Len(GroupArr(0)) - 3)
                                   MessageBox.Show("Group(s) belongs to " + UserName + " - " & strGroupName )
                            End If
                        Next
                    End If
                    '' Get primary Group
                    strPrimaryGroup = GetPrimaryGroupName(UserName)
                    If strPrimaryGroup.Length > 0 Then
                         MessageBox.Show("Primary Group belongs to " + UserName + " - " & strPrimaryGroup )
                    End If
    
                End If
            Catch exc As Exception
                MessageBox.Show(ex.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
                Exit Sub
            Finally
                search.Dispose()
            End Try
        End Sub
    Just pass the user name.
    __________________
    Rate the posts that helped you

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    172

    Re: Active Directory

    Thanks a lot

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