[Solved]LDAP query for a specific user
#1
Posted 16 July 2010 - 01:17 PM
I've seen the codes for getting info on the current user logged in but what I need to do is query for a specific user and I can't seem to locate the proper example...
any ideas?
#2
Posted 19 July 2010 - 12:09 PM
#3
Posted 19 July 2010 - 12:17 PM
<!-- m -->http://technet.micro... ... UsingLDIFE<!-- m -->
#4
Posted 19 July 2010 - 12:32 PM
#5
Posted 20 July 2010 - 05:41 PM
is there any way to use
ldap://ldap.example.com/dc=example,dc=com??sub?(sn=Jensen)
in COM and get it to work? (with my criteria of course)
#6
Posted 21 July 2010 - 12:33 PM
I have this that does work for me using it in ahk
Dim firstName, lastName
lastName = "Doe"
firstName = "Jane"
Set conn = createobject("ADODB.Connection")
conn.provider = "ADsDSOObject"
conn.open "Active Directory Provider"
query = "<LDAP://myLDAP>;(&(objectclass=user)(objectcategory=person)(sn=" & lastName & ")(&(givenName=" & firstName & ")));distinguishedname,cn,employeeid,mail,givenname,sn,middlename,samaccountname,displayname,department,division,bhnadpmanagerid,manager;subtree"
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.Properties("SearchScope") = 2
cmd.Properties("Page Size") = 500
cmd.CommandText = query
Set rs = cmd.Execute
While not rs.eof
msgbox rs.Fields("department").Value
rs.MoveNext
Wend
Any help to convert it to COM? My attempts at it are failing
#7
Posted 22 July 2010 - 12:45 PM
#8
Posted 22 July 2010 - 01:07 PM
#9
Posted 22 July 2010 - 01:42 PM
COM_Init()
lastName = Doe
firstName = Jane
connProv := "ADsDSOObject"
connOpen := "Active Directory Provider"
Query := "<LDAP://corp>;(&(objectclass=user)(objectcategory=person)(sn=" lastName ")(&(givenName=" firstName ")));distinguishedname,cn,employeeid,mail,givenname,sn,middlename,samaccountname,displayname,department,division,bhnadpmanagerid,manager;subtree"
oConn := COM_CreateObject("ADODB.Connection")
oComm := COM_CreateObject("ADODB.Command")
COM_Invoke(oConn, "Provider", connProv)
COM_Invoke(oConn, "Open", connOpen)
COM_Invoke(oComm, "ActiveConnection", "+" . oConn)
COM_Invoke(oComm, "Properties", "SearchScope", "2")
COM_Invoke(oComm, "Properties", "Page Size", "500")
COM_Invoke(oComm, "ComandText", Query)
result := COM_Invoke(oComm, "Execute")
MsgBox % result
COM_Invoke(oConn, "Close")
COM_Release(oConn)
COM_Release(oComm)
COM_Term()
#10
Posted 22 July 2010 - 06:44 PM
Here's what I came up with...and it got me the results...
I had to change the query statement though to sql...the other way I had it would give me Commandtext errors....
Is this pretty accurate code wise? I want to make sure I'm spot on before I mark this solved.
COM_init()
COM_CoInitialize()
lastName = Doe
firstName = Jane
connProv := "ADsDSOObject"
connOpen := "Active Directory Provider"
Query := "<LDAP://myldapserver>;(&(objectclass=user)(objectcategory=person)(&(sn=" lastName ")(givenName=" firstName ")));distinguishedname,cn,employeeid,mail,givenname,sn,middlename,samaccountname,displayname,department,division,bhnadpmanagerid,manager;subtree"
oConn := COM_CreateObject("ADODB.Connection")
oComm := COM_CreateObject("ADODB.Command")
COM_Invoke(oConn, "Provider", connProv)
COM_Invoke(oConn, "Open", connOpen)
COM_Invoke(oComm, "ActiveConnection", "+" . oConn)
COM_Invoke(oComm, "Properties", "SearchScope", "2")
COM_Invoke(oComm, "Properties", "Page Size", "500")
COM_Invoke(oComm, "CommandText", Query)
adoExecute := COM_Invoke(oComm, "Execute")
Loop
{
If COM_Invoke(adoExecute, "EOF")
Break
exFields := COM_Invoke(adoExecute, "Fields")
exField := COM_Invoke(exFields, "Item", "cn")
result .= COM_Invoke(exField, "Name") . ": " . COM_Invoke(exField, "Value") . "`r`n"
COM_Invoke(adoExecute, "MoveNext")
COM_Release(exField)
}
MsgBox % result
COM_Invoke(oConn, "Close")
COM_Release(exFields)
COM_Release(exField)
COM_Release(oConn)
COM_Release(oComm)
COM_CoUnInitialize()
COM_Term()
EDIT: Update code to for multiple matches...
EDIT2: I figured out what was wrong with my ldap syntax and fixed it...
#11
Posted 23 July 2010 - 12:17 PM
#12
Posted 23 July 2010 - 12:22 PM
#13
hotkeyd
Posted 27 October 2010 - 10:15 AM
Looking at the script posted above, how do I send
Properties - User ID, Password & Encrypt Password.
COM_Invoke(oComm, "Properties", "User ID", "username") COM_Invoke(oComm, "Properties", "Password", "password") COM_Invoke(oComm, "Properties", "Encrypt Password", "False")
When I try that I get:
Function Name: "Properties"
ERROR: Invalid number of parameters. (0x8002000E)
ERROR2: Exception occurred. (0x80020009)
Will Continue ?
Thanks
#14
hotkeyd
Posted 01 November 2010 - 04:11 PM




