|
-
Jun 22nd, 2006, 07:27 AM
#1
Thread Starter
Lively Member
Solved] retrieve information from Active Directory
Hi,
I would like to write a vb-code to retrieve information from our active directory. How do i do this?
I have tried 10 several codes, surfed the web and I just don't manage to do it.
I always have problems with the "Imports System.DirectoryServices", is underlined in green & using
directorysearcher or directoryentry does not work.
Last edited by darktown; Jun 23rd, 2006 at 09:07 AM.
There is an easy way, there is a hard way and there is My way of doing things!
-
Jun 22nd, 2006, 07:51 AM
#2
Re: [2005] retrieve information from Active Directory
Can you post the code? And what is the exact error/warning message that you are getting?
Take a look at this article
http://channel9.msdn.com/Showpost.aspx?postid=132740
Have you added the reference to System.DirectoryServices.DLL from Add References menu option?
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 22nd, 2006, 07:55 AM
#3
Thread Starter
Lively Member
Re: [2005] retrieve information from Active Directory
oh, thx for the info, i am trying some stuff now
There is an easy way, there is a hard way and there is My way of doing things!
-
Jun 22nd, 2006, 08:23 AM
#4
Thread Starter
Lively Member
Re: [2005] retrieve information from Active Directory
okey, this works:
VB Code:
Dim objSearch As New DirectorySearcher()
objSearch.SearchRoot = New DirectoryEntry("LDAP://verelst.nw", "jkhadmin", "Tidus05")
objSearch.Filter = "(&(objectclass=user)(objectcategory=person))"
objSearch.SearchScope = SearchScope.Subtree
objSearch.PropertiesToLoad.Add("cn")
Dim colQueryResults As SearchResultCollection
colQueryResults = objSearch.FindAll()
Dim objResult As SearchResult
For Each objResult In colQueryResults
Label1.Text += objResult.Properties("cn")(0) & vbCrLf
Next
the question: where can i find a list of the attribute names so I can make a nice overview?
There is an easy way, there is a hard way and there is My way of doing things!
-
Jun 22nd, 2006, 08:38 AM
#5
Re: [2005] retrieve information from Active Directory
 Originally Posted by darktown
the question: where can i find a list of the attribute names so I can make a nice overview?
I did not understand what exactly dod you mean by attribute names.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 22nd, 2006, 09:06 AM
#6
Thread Starter
Lively Member
Re: [2005] retrieve information from Active Directory
VB Code:
Dim objSearch As New DirectorySearcher()
objSearch.SearchRoot = New DirectoryEntry("LDAP://verelst.nw", "jkhadmin", "Tidus05")
objSearch.Filter = "(&(objectclass=user)(objectcategory=person))"
objSearch.SearchScope = SearchScope.Subtree
objSearch.PropertiesToLoad.Add("cn")
objSearch.PropertiesToLoad.AddRange(New String() {"cn", "sn", "test"})
Dim colQueryResults As SearchResultCollection
colQueryResults = objSearch.FindAll()
Dim objResult As SearchResult
For Each objResult In colQueryResults
Label1.Text += "<br/>" & objResult.Properties("cn")(0) & "|" & objResult.GetDirectoryEntry().Properties("sAMAccountName").Value.ToString()
Next
I mean "saMAccountName", I have searched the web but can't seem to find the attributename for the "companyname, telephone , website and others"..
When you look in the properties of a user in you AD, you"ll find these fields, i want to retrieve them & alter them.
I have found a way to retrieve them now, am looking how to retrieve all the fields I want & then I want to search & edit the ones I want
I have found this link: http://www.computerperformance.co.uk..._directory.htm
But it doesn't work.
Response.Write("|" & objResult.GetDirectoryEntry().Properties("mail").Value.ToString)
Get a "object not set to a reference" error.. use the "new" keyword ..
Last edited by darktown; Jun 22nd, 2006 at 09:16 AM.
There is an easy way, there is a hard way and there is My way of doing things!
-
Jun 22nd, 2006, 09:54 AM
#7
Thread Starter
Lively Member
Re: [2005] retrieve information from Active Directory
found a nice article and it works: http://forums.asp.net/thread/1309113.aspx
But i also want to be able to edit the field, there is a link but it's all in C-sharp and i don't understand it.
could someone explain & intergrate it in my code :
Code:
Dim filter As String = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", Environment.UserName)
Dim entry As New DirectoryEntry("LDAP://verelst.nw", "jkhadmin", "Tidus05")
Dim searcher As New DirectorySearcher(entry, filter, New String() {"displayName", "streetAddress", "l", "st", "postalCode", "physicalDeliveryOfficeName", "mail"})
Dim fullName As String = ""
Try
Dim result As SearchResult = searcher.FindOne()
If Not IsNothing(result) Then
If (result.Properties.Contains("displayName")) Then
lblName.Text = "Name"
txtCity.Text = result.Properties("displayName")(0).ToString
End If
If (result.Properties.Contains("streetAddress")) Then
lblAddress.Text = result.Properties("streetAddress")(0)
End If
If (result.Properties.Contains("l")) Then
lblcity.Text = result.Properties("l")(0)
End If
If (result.Properties.Contains("st")) Then
lblstate.Text = result.Properties("st")(0)
End If
If (result.Properties.Contains("postalCode")) Then
lblzip.Text = result.Properties("postalCode")(0)
End If
If (result.Properties.Contains("physicalDeliveryOfficeName")) Then
lblphone.Text = result.Properties("physicalDeliveryOfficeName")(0)
End If
If (result.Properties.Contains("mail")) Then
lblDesc.Text = result.Properties("mail")(0)
End If
End If
Catch
Throw
Finally
If Not (entry Is Nothing) Then
entry.Dispose()
End If
If Not (searcher Is Nothing) Then
searcher.Dispose()
End If
End Try
There is an easy way, there is a hard way and there is My way of doing things!
-
Jun 23rd, 2006, 01:52 AM
#8
Re: [2005] retrieve information from Active Directory
There are lot of converteres over there which can convert C# code in VB.NET and vice versa. Try one of those.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 23rd, 2006, 09:07 AM
#9
Thread Starter
Lively Member
Re: [2005] retrieve information from Active Directory
Don't bother found my solution
There is an easy way, there is a hard way and there is My way of doing things!
-
Dec 5th, 2007, 08:08 PM
#10
Lively Member
Re: Solved] retrieve information from Active Directory
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|