P
Phil Kelly
Hi!
I hope someone can help me here because I'm tearing my hair out (what little
there is of it!) trying to figure out what's going on with the code below.
I'm passing an Active Directory CN of a user object (like
CN=Phil,OU=Users,DC=Test,DC=local) to the doRep() function, then have the
function search for the user in AD ('FindOne')
Then, I'm trying to get the code to msgbox the directory entry name.... but
we never seem to get that far; nothing turns up in a msgbox
Now, I'm not that au fait with vb .NET but I'm finding the challenge to be
superb. I really hope someone will show me the error of my ways...!
Thanks
Phil
Public Sub doRep(ByVal objectName As String)
' Create a 'DirectoryEntry' object to search.
Dim mySearchRoot As New DirectoryEntry("LDAP://DC=test,DC=local")
Dim myRepDirectorySearcher As New DirectorySearcher(mySearchRoot)
myRepDirectorySearcher.Filter = objectName
' Get the first entry of the search.
Dim myRepSearchResult As SearchResult = myRepDirectorySearcher.FindOne()
MsgBox(myRepDirectorySearcher.Filter)
If Not (myRepSearchResult Is Nothing) Then
' Get the 'DirectoryEntry' that corresponds to 'myRepSearchResult'.
Dim myDirectoryEntry As DirectoryEntry =
myRepSearchResult.GetDirectoryEntry()
MsgBox(myDirectoryEntry.Name)
Dim myRepSearchResultPath As String = myRepSearchResult.Path
MsgBox(myRepSearchResultPath)
End If
End Sub
I hope someone can help me here because I'm tearing my hair out (what little
there is of it!) trying to figure out what's going on with the code below.
I'm passing an Active Directory CN of a user object (like
CN=Phil,OU=Users,DC=Test,DC=local) to the doRep() function, then have the
function search for the user in AD ('FindOne')
Then, I'm trying to get the code to msgbox the directory entry name.... but
we never seem to get that far; nothing turns up in a msgbox
Now, I'm not that au fait with vb .NET but I'm finding the challenge to be
superb. I really hope someone will show me the error of my ways...!
Thanks
Phil
Public Sub doRep(ByVal objectName As String)
' Create a 'DirectoryEntry' object to search.
Dim mySearchRoot As New DirectoryEntry("LDAP://DC=test,DC=local")
Dim myRepDirectorySearcher As New DirectorySearcher(mySearchRoot)
myRepDirectorySearcher.Filter = objectName
' Get the first entry of the search.
Dim myRepSearchResult As SearchResult = myRepDirectorySearcher.FindOne()
MsgBox(myRepDirectorySearcher.Filter)
If Not (myRepSearchResult Is Nothing) Then
' Get the 'DirectoryEntry' that corresponds to 'myRepSearchResult'.
Dim myDirectoryEntry As DirectoryEntry =
myRepSearchResult.GetDirectoryEntry()
MsgBox(myDirectoryEntry.Name)
Dim myRepSearchResultPath As String = myRepSearchResult.Path
MsgBox(myRepSearchResultPath)
End If
End Sub