Get user information Active Diretory VBA + AHK
Posted: 07 Feb 2015, 13:28
Hello friends, I want to make the AutoHotkey harvest user information in Active Directory.
I have no knowledge of VBA and just dare to program something in AHK (is the only one I do some work cpodigo)
What I need is the following, enter the user Login (userPrincipalName), using an InputBox
![Image](http://nsae02.casimages.net/img/2015/02/06/150206081128170205.jpg)
Then he brings the following information in a MsgBox
![Image](http://nsae02.casimages.net/img/2015/02/06/150206081219733856.jpg)
Full_name = cn
Site = company
City = l
Email = mail
A friend made in Excel with VBA, however, did not know anything about VBA and not know how to put that information collected on variables.
Below is what I tried to do without success:
I have no knowledge of VBA and just dare to program something in AHK (is the only one I do some work cpodigo)
What I need is the following, enter the user Login (userPrincipalName), using an InputBox
![Image](http://nsae02.casimages.net/img/2015/02/06/150206081128170205.jpg)
Then he brings the following information in a MsgBox
![Image](http://nsae02.casimages.net/img/2015/02/06/150206081219733856.jpg)
Full_name = cn
Site = company
City = l
Email = mail
A friend made in Excel with VBA, however, did not know anything about VBA and not know how to put that information collected on variables.
Below is what I tried to do without success:
Code: Select all
F5::
InputBox,userPrincipalName,login,
userPrincipalName = %userPrincipalName%@empresa.corp ;@empresa.corp is domain of AD
code =
(
Atctive_DirectoryQuery(ByVal TypeFilter As String, ByVal InformationSought As String, ByVal SearchResult As String) As String
; Get the domain string ("dc=domain, dc=local")
strDomain := ComObjGet("LDAP://rootDSE").Get("defaultNamingContext")
; ADODB Connection to AD
objConnection := ComObjCreate("ADODB.Connection")
objConnection.Open("Provider=ADsDSOObject")
; Connection
objCommand := ComObjCreate("ADODB.Command")
objCommand.ActiveConnection := objConnection
; Search the AD recursively, starting at root of the domain
objCommand.CommandText := "<LDAP://" . strDomain . ">;(&(objectCategory=User)" . "(" . TypeFilter . "=" . InformationSought . "));" . TypeFilter . "," . SearchResult . ";subtree"
; RecordSet
objRecordSet := objCommand.Execute
If (objRecordSet.RecordCount = 0)
;return "No Data" ; no records returned
Else
{
return objRecordSet.Fields(SearchResult) ; return value
}
; Close connection
objConnection.Close
)
MsgBox % ws.Eval("SearchResult")