Hi everyone,
Sorry for cross posting, but I wanted to try and put this where it would
be more visible to everyone... :-)
I need to find a way to be able to search for entries in our ADS tree. I
have it working, but I have to pass it my username/password in order to
search it. What I would like to do is pass the username/password to the
DirectoryEntry as parameters without having to hard code a
username/password. I know how to get the username, but how can I pass the
password (i.e. how can I get the password in order to pass it?). For
example:
strUsername = "UserA"
strAuthUsername = "Admin" <--- Hard coded = BAD
strAuthPassword = "Password" <--- Hard coded = BAD
strDomain = "ADS"
strServer = "ads.somewhere. com"
strFilter = ""
Public Shared Function GetUser_Directo ryEntry(ByVal strUsername As
String, ByVal strAuthUsername As String, ByVal strAuthPassword As String,
ByVal strDomain As String, ByVal strServer As String, ByVal strFilter As
String) As DirectoryEntry
Dim strLoginName As String = String.Format(" {0}\{1}",
strDomain.Trim, strAuthUsername .Trim)
Dim deSearchRoot As New
DirectoryEntry( String.Format(" LDAP://{0}", strDomain.Trim) , strLoginName,
strAuthPassword .Trim, AuthenticationT ypes.Secure)
Dim de As DirectoryEntry
Try
Dim dsUser As DirectorySearch er = New
DirectorySearch er(deSearchRoot ,
String.Format(" (&(objectCatego ry=person)(sAMA ccountName={0}) )",
strUsername.Tri m))
Dim srcUser As SearchResultCol lection = dsUser.FindAll( )
If IsNothing(srcUs er) Then
Throw New Utilities.Excep tionHandler("Co uld not find
user in ADS tree")
Else
de = srcUser(0).GetD irectoryEntry
End If
Catch ex As Exception
Return Nothing
End Try
Return de
End Function
Thanks for any assistance!
Chad
Sorry for cross posting, but I wanted to try and put this where it would
be more visible to everyone... :-)
I need to find a way to be able to search for entries in our ADS tree. I
have it working, but I have to pass it my username/password in order to
search it. What I would like to do is pass the username/password to the
DirectoryEntry as parameters without having to hard code a
username/password. I know how to get the username, but how can I pass the
password (i.e. how can I get the password in order to pass it?). For
example:
strUsername = "UserA"
strAuthUsername = "Admin" <--- Hard coded = BAD
strAuthPassword = "Password" <--- Hard coded = BAD
strDomain = "ADS"
strServer = "ads.somewhere. com"
strFilter = ""
Public Shared Function GetUser_Directo ryEntry(ByVal strUsername As
String, ByVal strAuthUsername As String, ByVal strAuthPassword As String,
ByVal strDomain As String, ByVal strServer As String, ByVal strFilter As
String) As DirectoryEntry
Dim strLoginName As String = String.Format(" {0}\{1}",
strDomain.Trim, strAuthUsername .Trim)
Dim deSearchRoot As New
DirectoryEntry( String.Format(" LDAP://{0}", strDomain.Trim) , strLoginName,
strAuthPassword .Trim, AuthenticationT ypes.Secure)
Dim de As DirectoryEntry
Try
Dim dsUser As DirectorySearch er = New
DirectorySearch er(deSearchRoot ,
String.Format(" (&(objectCatego ry=person)(sAMA ccountName={0}) )",
strUsername.Tri m))
Dim srcUser As SearchResultCol lection = dsUser.FindAll( )
If IsNothing(srcUs er) Then
Throw New Utilities.Excep tionHandler("Co uld not find
user in ADS tree")
Else
de = srcUser(0).GetD irectoryEntry
End If
Catch ex As Exception
Return Nothing
End Try
Return de
End Function
Thanks for any assistance!
Chad
Comment