Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. getting group information

getting group information

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bis1982
    wrote on last edited by
    #1

    Hello, I'm trying to get the group in which a user is sitting. I searched and found an artikle here. Converted it from c# to VB.NET and made some changes. This is the code: Dim entry As New sys.DirectoryEntry("LDAP://WMU") Dim search As sys.DirectorySearcher = New sys.DirectorySearcher(entry) search.Filter = String.Format("(cn=*)", userName) search.PropertiesToLoad.Add("memberOf") Dim groupsList As System.Text.StringBuilder = New System.Text.StringBuilder groupsList.Append("test") result = search.FindOne() If Not result Is Nothing Then Dim groupCount As Integer groupCount = result.Properties.Count Dim counter As Integer For counter = 0 To groupCount - 1 Step counter + 1 MessageBox.Show("in for loop") If result.Properties.Contains("memberOf") Then MessageBox.Show("In If statement") groupsList.Append(CType(result.Properties("memberOf")(counter), String)) groupsList.Append("|") End If Next End If groupsList.Length -= 1 'remove the last "|" symbol Return groupsList.ToString() After some tests, i noticed that the code in the If condition never gets executed. So in other words, the property memberOf is not available. What can i do to get it available? Thanks in advance Bis

    S 1 Reply Last reply
    0
    • B Bis1982

      Hello, I'm trying to get the group in which a user is sitting. I searched and found an artikle here. Converted it from c# to VB.NET and made some changes. This is the code: Dim entry As New sys.DirectoryEntry("LDAP://WMU") Dim search As sys.DirectorySearcher = New sys.DirectorySearcher(entry) search.Filter = String.Format("(cn=*)", userName) search.PropertiesToLoad.Add("memberOf") Dim groupsList As System.Text.StringBuilder = New System.Text.StringBuilder groupsList.Append("test") result = search.FindOne() If Not result Is Nothing Then Dim groupCount As Integer groupCount = result.Properties.Count Dim counter As Integer For counter = 0 To groupCount - 1 Step counter + 1 MessageBox.Show("in for loop") If result.Properties.Contains("memberOf") Then MessageBox.Show("In If statement") groupsList.Append(CType(result.Properties("memberOf")(counter), String)) groupsList.Append("|") End If Next End If groupsList.Length -= 1 'remove the last "|" symbol Return groupsList.ToString() After some tests, i noticed that the code in the If condition never gets executed. So in other words, the property memberOf is not available. What can i do to get it available? Thanks in advance Bis

      S Offline
      S Offline
      sasidar_d
      wrote on last edited by
      #2

      Bis, I have already replied to your previous thread, I will also paste the code snippet which i am using for your further reference Dim entry As New DirectoryEntry ("LDAP://JANDBINDIA.com", .txtUsername.Value.ToString, .txtpwd.Value.ToString) Dim search As DirectorySearcher = New DirectorySearcher(entry) search.Filter = "(&(objectClass=user)(objectCategory=person))" search.PropertiesToLoad.Add("memberOf") Dim result As SearchResult For Each result In search.FindAll() If result.Properties.Contains("memberOf") Then Response.Write(result.Properties("memberOf")(0)) Response.Write(" ") End If Next This time you will get it, i am allowing to do the process only for authorized users , probably you can hard code the same r you can leave the parameters blank. but make sure that you have mentioned the .com extension for your domain name which is very important Sasidar

      B 1 Reply Last reply
      0
      • S sasidar_d

        Bis, I have already replied to your previous thread, I will also paste the code snippet which i am using for your further reference Dim entry As New DirectoryEntry ("LDAP://JANDBINDIA.com", .txtUsername.Value.ToString, .txtpwd.Value.ToString) Dim search As DirectorySearcher = New DirectorySearcher(entry) search.Filter = "(&(objectClass=user)(objectCategory=person))" search.PropertiesToLoad.Add("memberOf") Dim result As SearchResult For Each result In search.FindAll() If result.Properties.Contains("memberOf") Then Response.Write(result.Properties("memberOf")(0)) Response.Write(" ") End If Next This time you will get it, i am allowing to do the process only for authorized users , probably you can hard code the same r you can leave the parameters blank. but make sure that you have mentioned the .com extension for your domain name which is very important Sasidar

        B Offline
        B Offline
        Bis1982
        wrote on last edited by
        #3

        hello sasidar, Sorry to repost a question and thanks for replying. This time it works, but strangely if I give the extention drom the domain name, it doesn't work. Greetz Bis

        S 1 Reply Last reply
        0
        • B Bis1982

          hello sasidar, Sorry to repost a question and thanks for replying. This time it works, but strangely if I give the extention drom the domain name, it doesn't work. Greetz Bis

          S Offline
          S Offline
          sasidar_d
          wrote on last edited by
          #4

          Bis, What changes have you made to make it work. Sasidar

          B 1 Reply Last reply
          0
          • S sasidar_d

            Bis, What changes have you made to make it work. Sasidar

            B Offline
            B Offline
            Bis1982
            wrote on last edited by
            #5

            Sasidar Here is the code from the function; Private Function GetADUserGroups(ByVal userName As String) As String Dim entry As New sys.DirectoryEntry("LDAP://WMU", username, Password) Dim search As sys.DirectorySearcher = New sys.DirectorySearcher(entry) search.Filter = "(&(objectClass=user)(objectCategory=person))" 'String.Format("(cn=*)", userName) search.PropertiesToLoad.Add("memberOf") Dim groupsList As System.Text.StringBuilder = New System.Text.StringBuilder result = search.FindOne() If Not result Is Nothing Then Dim groupCount As Integer groupCount = result.Properties.Count Dim counter As Integer For Each result In search.FindAll() If result.Properties.Contains("memberOf") Then groupsList.Append(result.Properties("memberOf")(0)) groupsList.Append(NewLine) End If Next End If groupsList.Length -= 1 'remove the last "|" symbol Return groupsList.ToString() End Function Bis -- modified at 4:30 Thursday 15th June, 2006

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups