Hi Scott,
Thanks for the advice! The trouble is that it returns the same user
information again and again! Do I have to put a
For Each mySearchResultC oll In mySearcher.Find All()
and if so where???
I really appritiate the advice!
Thanks
<code>
Public Function GetUserInfo(ByV al inType As String) As String
Try
Dim sPath As String = "LDAP://netdomain.domai n.com"
'Dim SamAccount As String = Right(inSAM, Len(inSAM) -
InStr(inSAM, "\"))
'pass the user account and password for your Admin Account.
Dim myDirectory As New DirectoryEntry( sPath, "administrator" ,
"password")
Dim mySearcher As New DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user))")
mySearchResultC oll = mySearcher.Find All()
'I expect only one user from search result
Select Case mySearchResultC oll.Count
Case 0
Return "Null"
Exit Function
End Select
'Get the search result from the collection
mySearchResult = mySearchResultC oll.Item(0)
'Get the Properites, they contain the usefull info
myResultPropCol l = mySearchResult. Properties
'displayname, mail
'Retrieve from the properties collection the display name and
email of the user
myResultPropVal ueColl = myResultPropCol l.Item(inType)
Return CStr(myResultPr opValueColl.Ite m(0))
Catch ex As System.Exceptio n
'do some error return here.
End Try
End Function
"Scott Allen" wrote:
Hi Tim:
The filter seems to be looking for a specific user account by
including samAccountName. Have you tried removing it from the filter?
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 28 Mar 2005 23:59:03 -0800, "Tim::.." <myatix_at_hotm ail.com>
wrote:
Hi can someone please tell me how I change this directory service query so
that it searches through each record in the active directory and returns all
the accounts!
At the moment I can only get the query to return one account at a time!
I presume I have to create some kind of loop on the following so I return
all the users SAM info????
Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
I would be really grateful for any help!
Thanks
<code>
Public Function GetUserInfo(ByV al inSAM As String, ByVal inType As String)
As String
Try
Dim sPath As String = "LDAP://netdomain.domai n.com"
Dim SamAccount As String = Right(inSAM, Len(inSAM) -
InStr(inSAM, "\"))
'pass the user account and password for your Admin Account.
Dim myDirectory As New DirectoryEntry( sPath, "administrator" ,
"password")
Dim mySearcher As New DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
SamAccount & "))")
mySearchResultC oll = mySearcher.Find All()
</code>