Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass parameter/filter to LDAP

Status
Not open for further replies.

99Chuck99

Programmer
Dec 11, 2003
67
US
Hi, hope someone can help me with this. I not up to speed on LDAP. What I would like to do is get the users ID (SAMAccountname) and pass it as a filter in the code listed below. I hope that made sence....
Thanks
Chuck


<SCRIPT language=VBScript>

Sub Window_OnLoad

Dim objRootDSE, strDNSDomain, objCommand, objConnection
Dim strQuery, strBase, strFilter, strAttributes
Dim objRecordSet, strDN, strSAM, address
Dim strMAIL, strPHONE
Dim objUser, strValue


Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

strSAMAccountname=xxxxxxxxxx

strBase = "<LDAP://" & strDNSDomain & ">"

strFilter = "(&(sAMAccountname=" & strSAMAccountname & ")(objectClass=user))"

strAttributes ="mail,sAMAccountName,telephoneNumber"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery

Set objRecordSet = objCommand.Execute


strMAIL = objRecordSet.Fields("mail")
strPHONE = objRecordSet.Fields("telephoneNumber")

Presenter_Phone.value = strPHONE
Presenter_EMAIL.VALUE = StrMAIL

objConnection.Close


end sub

</SCRIPT>
 
>strSAMAccountname=xxxxxxxxxx
Not sure what you mean. If you have that xxx..., you can sure pass it to the filter as shown. If what you mean is that you don't get the xxx... yet, this is one way to get it for the logged in user running the script in person.
[tt] strSAMAccountname=createobject("wscript.network").username[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top