Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved]LDAP query for a specific user


  • Please log in to reply
13 replies to this topic
frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
Hello,

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?

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
bump

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
using your subject as is within google i found this wheihc is command line which you should be able toe xecute with or without ahk
<!-- m -->http://technet.micro... ... UsingLDIFE<!-- m -->
Never lose.
WIN or LEARN.

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
don't I feel dumb, I didn't think to use the subject as search criteria in google... thanks tank I'll check it out

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
I've been trying all sorts of things, I'm missing something obviously

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)

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
bump

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

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
bump anyone?

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
post what you tried
Never lose.
WIN or LEARN.

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
Everything up to including ActiveConnection is fine, everything below just isn't working right and gets errors....

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()


frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
ok I got something that works, after working through this, I found my first mistake which was a mispelling of the word Command...

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...

frescalus
  • Members
  • 163 posts
  • Last active: Dec 14 2012 09:34 PM
  • Joined: 19 Nov 2009
marked thread solved, thanks for all the help

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Sorry for taking so long to follow up but I knew you could do it
Never lose.
WIN or LEARN.

hotkeyd
  • Guests
  • Last active:
  • Joined: --
Hi
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 :)

hotkeyd
  • Guests
  • Last active:
  • Joined: --
Anyone any ideas ?