Jump to content
Sign in to follow this  

Retrieve information from Active Directory

Recommended Posts


Please help, I'm new to AutoIt. This should be a sinch for you programmers :whistle:

I wan't to retrieve user information such as "Office" and "Description" for the currently logged on user from active directory and assign the data to a variable that I create.

Ex. If John Doe is logged on to the network, in active directory, his information is as follows:

Office=Rm 513


I want to create 2 variables $useroffice and $userdescription and populate these variables with the corresponding active directory data.

I am not a programmer, I'm simply trying to hack this into place! Any help would be GREATLY appreciated.


Share this post

Link to post
Share on other sites

The following code is from a script I use to find users and do some processing on them. Perhaps it may point you in the right direction.

Func btnSearchonclick()
 $UserDomain = "dc=engineering,dc=bb,dc=wan"
 $l_UserId = GUICtrlRead($edtUser)
    Local $objCommand = ObjCreate("ADODB.Command")
    Local $objConnection = ObjCreate("ADODB.Connection")
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider")
    $objCommand.ActiveConnection = $objConnection
    Local $strBase = "<GC://" & $UserDomain & ">"
    Local $strFilter = "(&(objectCategory=person)(objectClass=user)(cn=*" & $l_UserId & "*))"
    Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName"
    Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"

 $objCommand.CommandText = $strQuery
    $objCommand.Properties ("Page Size") = 100
    $objCommand.Properties("Sort On") = "cn"
    $objCommand.Properties ("Timeout") = 30
    $objCommand.Properties ("Cache Results") = False
    $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE
    Local $objRecordSet = $objCommand.Execute
    While Not $objRecordSet.EOF
        $strName = $objRecordSet.Fields ("sAMAccountName").Value
        $strdisplayName = $objRecordSet.Fields ("displayName").value
        $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value
  GUICtrlCreateListViewItem($strName&"|"&$strdisplayName&"|"&$strdistinguishedName, $lstResults)
Edited by sandyd

----[ SandyD ]---

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.