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
csharphelpquestion
6 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. This is the code: Private Function GetADUserGroups(ByVal userName As String) As String Dim search As sys.DirectorySearcher = New sys.DirectorySearcher 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 MessageBox.Show(groupCount) Dim counter As Integer For counter = 0 To groupCount - 1 Step counter + 1 groupsList.Append(CType(result.Properties("memberOf").Item(counter), String)) groupsList.Append("|") Next End If groupsList.Length -= 1 'remove the last "|" symbol Return groupsList.ToString() End Function if i try to run it i get a System.NullReferenceException in the for loop. does anyone know what the problem is? any other ideas are welcome. 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. This is the code: Private Function GetADUserGroups(ByVal userName As String) As String Dim search As sys.DirectorySearcher = New sys.DirectorySearcher 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 MessageBox.Show(groupCount) Dim counter As Integer For counter = 0 To groupCount - 1 Step counter + 1 groupsList.Append(CType(result.Properties("memberOf").Item(counter), String)) groupsList.Append("|") Next End If groupsList.Length -= 1 'remove the last "|" symbol Return groupsList.ToString() End Function if i try to run it i get a System.NullReferenceException in the for loop. does anyone know what the problem is? any other ideas are welcome. thanks in advance Bis

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

      Hi, I would like to give some suggestions so that i will work for you, as i have changed the same in my testing environment and it is working . . . Include the following line as the first line inside the function Dim entry As New DirectoryEntry("LDAP://") Change the second line as follows Dim search As DirectorySearcher = New DirectorySearcher(entry) include a if condition inside the for loop and it should appear like this For counter = 0 To groupCount - 1 Step counter + 1 If result.Properties.Contains("memberOf") Then groupsList.Append(CType(result.Properties("memberOf").Item(counter), String)) groupsList.Append("|") End If Next i hope you would have declared result as search result Hope this will

      B 2 Replies Last reply
      0
      • S sasidar_d

        Hi, I would like to give some suggestions so that i will work for you, as i have changed the same in my testing environment and it is working . . . Include the following line as the first line inside the function Dim entry As New DirectoryEntry("LDAP://") Change the second line as follows Dim search As DirectorySearcher = New DirectorySearcher(entry) include a if condition inside the for loop and it should appear like this For counter = 0 To groupCount - 1 Step counter + 1 If result.Properties.Contains("memberOf") Then groupsList.Append(CType(result.Properties("memberOf").Item(counter), String)) groupsList.Append("|") End If Next i hope you would have declared result as search result Hope this will

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

        Thanks for the reply, but still have some problems :( Made the changes you told me, but still doesn't work. Maybe it's the given username. I just give eg John. Is this correct or do you need to specify your domain as well? Bis

        S 1 Reply Last reply
        0
        • S sasidar_d

          Hi, I would like to give some suggestions so that i will work for you, as i have changed the same in my testing environment and it is working . . . Include the following line as the first line inside the function Dim entry As New DirectoryEntry("LDAP://") Change the second line as follows Dim search As DirectorySearcher = New DirectorySearcher(entry) include a if condition inside the for loop and it should appear like this For counter = 0 To groupCount - 1 Step counter + 1 If result.Properties.Contains("memberOf") Then groupsList.Append(CType(result.Properties("memberOf").Item(counter), String)) groupsList.Append("|") End If Next i hope you would have declared result as search result Hope this will

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

          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 Kris

          S 1 Reply Last reply
          0
          • B Bis1982

            Thanks for the reply, but still have some problems :( Made the changes you told me, but still doesn't work. Maybe it's the given username. I just give eg John. Is this correct or do you need to specify your domain as well? Bis

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

            Hi, Try giving the domain name with the com extension. then you will get it Sasidar

            1 Reply Last reply
            0
            • B Bis1982

              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 Kris

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

              Kris, Can you post your code here so that let us have a look ? Sasidar

              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