getting group information
-
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
-
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
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 -
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 -
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
-
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