Jump to content

Active Directory issue


Recommended Posts

Hi guys,

I've been playing around with the adfunctions.au3 UDF and I'm having a strange issue. Hope one of you can shed some light on it.

I am using the latest AutoIt v3.2.12.1 and am using the (latest?) adfunctions.au3 v3.1.3 from this location clickme

My test code (below) is a snippet I found in this post by Water who appears to be using the same versions as I am.

#include <adfunctions.au3>
#include <array.au3>                                    ; This line can be deleted
Global $DCList, $LastLogin=0
_ADListDomainControllers($DCList)
_ArrayDisplay($DCList)                                  ; This line can be deleted
For $i =1 to $DCList[0]
    $sTmp = StringSplit($DCList[$i],",")
    $sTmp = StringSplit($sTmp[1],"CN=",1)
    $strHostServer = $sTmp[2]
    $sTmp = _ADGetLastLoginDate(@username)
    ConsoleWrite($strHostServer & ": " & $sTmp & @lf)   ; This line can be deleted
    If $sTmp > $LastLogin Then $LastLogin = $sTmp
Next
ConsoleWrite("LastLogin: " & $LastLogin & @lf)          ; This line can be deleted

when I attempt to run it I get a couple COM error pop-ups (pop-up example attached) and this in the console:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "I:\Administrators\AutoitScripts\AD_inactive\OtherADtest.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>15:11:22 Starting AutoIt3Wrapper v.1.10.1.14  Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X86  ANSI)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
+>15:11:22 AU3Check ended.rc:0
>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "I:\Administrators\AutoitScripts\AD_inactive\OtherADtest.au3"  
C:\Program Files\AutoIt3\Include\adfunctions.au3 (1086) : ==> Object referenced outside a "With" statement.:
$objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base"
$objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" )^ ERROR
->15:11:24 AutoIT3.exe ended.rc:1
+>15:11:25 AutoIt3Wrapper Finished
>Exit code: 1   Time: 3.080

Any thoughts on how I should proceed?

-Spook

post-7657-1229724424_thumb.jpg

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I should have mentioned that the PC running this is a member of an AD domain.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Hi SpookMeister,

to make sure that it's a problem with adfunctions could you please download ADExplorer from www.sysinternals.com (now M$)? No installation is required - just run the exe. Open the default domain / DC=x,DC=y (your domain) / OU=Domain Controllers. This should give you a list of all Domain Controllers (as the au3 skript should do).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It does, I am able to browse through everything using that utility.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • Developers

It helps when you add the ComEventHandler to your script. this will allow you show the proper description about the error.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Jos,

Can I get some more info on that? Where/how etc. A search of the forums only returns this post, and I don't know what you are refering to.

-Spook

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • Developers

Jos,

Can I get some more info on that? Where/how etc. A search of the forums only returns this post, and I don't know what you are refering to.

-Spook

It is explained in the helfile.. here is an example:

; Init objects
$UserName = 'Robert'
$Password = 'Wil"ma'
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 
$strComputer = @ComputerName
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
;$objGroup = ObjGet("WinNT://" & $strComputer & "/Users,group")
; Read in lines of text until the EOF is reached
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", "Test User")
$objUser.Put ("Description", "Test User description")
$objUser.SetInfo
;Add user to group 
;$objGroup.Add($objUser.ADsPath)
;
;
; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
                "Description is: " & $oMyError.description  & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The adfunctions udf includes a COM error handler.

The pop-up I attached is an example.

The pop-ups reference the <<-- commented -->> lines in this snippet of the adfunctions udf code below:

; _ADListDomainControllers
; Retrieves the names of all domain controllers in the current Domain
Func _ADListDomainControllers(ByRef $DCList)
    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties("Page Size") = 1000
    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = "Select distinguishedName FROM 'LDAP://" & $strHostServer & "/ou=Domain Controllers," & $strDNSDomain & "' WHERE objectclass='computer'"
    
    $objRecordSet = $objCommand.Execute
    Dim $DCList[$objRecordSet.RecordCount + 1] ; <<-- line 1080 -->>
    $objRecordSet.MoveFirst ; <<-- line 1081 -->>
    
    Do
        $DCList[0] += 1
        
        $objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base"
        $objRecSet2 = $objCommand.Execute
        
        $objRecSet2.MoveFirst
        Do
            $temparray = $objRecSet2.Fields(0).Value
            $DCList[$DCList[0]] = $temparray[0]
            $objRecSet2.MoveNext
        Until $objRecSet2.EOF
        
        $objRecordSet.MoveNext
    Until $objRecordSet.EOF
    
    $objCommand = 0
    $objRecordSet = 0
    Return
EndFunc   ;==>_ADListDomainControllers

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Just a shot in the dark. What OS is your Active Directory running on? Windows 2000, Windows 2003?

I've seen a script where the coder distinguished between W2K and the rest.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

W2k3 AD environment.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I've moved everything from adfunctions.au3 into one script and added some consolewrites for debugging. Could you please run the following code and return the result?

My output looks like:

ObjCreate("ADODB.Connection"): 0

ObjGet("LDAP://RootDSE"): 0

ObjGet("LDAP:"): 0

ObjCreate("ADODB.Command"): 0

UBound($DCList): 6

Global $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
ConsoleWrite('ObjCreate("ADODB.Connection"): ' & @error & @CRLF)
$objConnection.ConnectionString = "Provider=ADsDSOObject"
$objConnection.Open("Active Directory Provider") ; Open connection to AD

Global $objRootDSE = ObjGet("LDAP://RootDSE")
ConsoleWrite('ObjGet("LDAP://RootDSE"): ' & @error & @CRLF)
Global $strDNSDomain = $objRootDSE.Get("defaultNamingContext") ; Retrieve the current AD domain name
Global $strHostServer = $objRootDSE.Get("dnsHostName") ; Retrieve the name of the connected DC
Global $strConfiguration = $objRootDSE.Get("ConfigurationNamingContext") ; Retrieve the Configuration naming context

Global $alt_userid = ""
Global $alt_password = ""
Global $objOpenDS = ObjGet("LDAP:")
ConsoleWrite('ObjGet("LDAP:"): ' & @error & @CRLF)

Global $loggedonusergroups ; populate this with the logged on user groups in your own app

#EndRegion  

$oMyError = ObjEvent("AutoIt.Error", "_ADDoError") ; Install a custom error handler

Global $DCList, $LastLogin=0
_ADListDomainControllers($DCList)
For $i =1 to $DCList[0]
    $sTmp = StringSplit($DCList[$i],",")
    $sTmp = StringSplit($sTmp[1],"CN=",1)
    $strHostServer = $sTmp[2]
    ;$sTmp = _ADGetLastLoginDate(@username)
    If $sTmp > $LastLogin Then $LastLogin = $sTmp
Next
Exit

Func _ADListDomainControllers(ByRef $DCList)
    $objCommand = ObjCreate("ADODB.Command")
    ConsoleWrite('ObjCreate("ADODB.Command"): ' & @error & @CRLF)
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties("Page Size") = 1000
    $objCommand.Properties("Searchscope") = 2
    
    $objCommand.CommandText = "Select distinguishedName FROM 'LDAP://" & $strHostServer & "/ou=Domain Controllers," & $strDNSDomain & "' WHERE objectclass='computer'"
    
    $objRecordSet = $objCommand.Execute
    Dim $DCList[$objRecordSet.RecordCount + 1]
    ConsoleWrite("UBound($DCList): " & UBound($DCList) & @CRLF)
    $objRecordSet.MoveFirst
    
    Do
        $DCList[0] += 1
        
        $objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base"
        $objRecSet2 = $objCommand.Execute
        
        $objRecSet2.MoveFirst
        Do
            $temparray = $objRecSet2.Fields(0).Value
            If IsArray($temparray) Then 
                $DCList[$DCList[0]] = $temparray[0]
            Else
                $DCList[$DCList[0]] = $temparray
            EndIf
            $objRecSet2.MoveNext
        Until $objRecSet2.EOF
        
        $objRecordSet.MoveNext
    Until $objRecordSet.EOF
    
    $objCommand = 0
    $objRecordSet = 0
    Return
EndFunc   ;==>_ADListDomainControllers

;  MyErrFunc
Func _ADDoError()
    $HexNumber = Hex($oMyError.number, 8)
    
    If $HexNumber = 80020009 Then
        SetError(3)
        Return
    EndIf
    
    If $HexNumber = "8007203A" Then
        SetError(4)
        Return
    EndIf
    
    If $HexNumber = 80005000 Then
        SetError(5)
        Return
    EndIf
    
    MsgBox(262144, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription & @CRLF & _
            "Script Line number is: " & $oMyError.scriptline)
    
    Select
        Case $oMyError.windescription = "Access is denied."
            $objConnection.Close
            $objConnection.Open("Active Directory Provider")
            SetError(2)
        Case 1
            SetError(1)
    EndSelect
    
EndFunc   ;==>_ADDoError

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I get two COM error pop-ups referencing line 44 and 46 which are these two lines respectively:

Dim $DCList[$objRecordSet.RecordCount + 1]

$objRecordSet.MoveFirst

The console output was:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "I:\Administrators\AutoitScripts\AD_inactive\OtherADtest.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>09:57:45 Starting AutoIt3Wrapper v.1.10.1.14  Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X86  ANSI)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
+>09:57:45 AU3Check ended.rc:0
>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "I:\Administrators\AutoitScripts\AD_inactive\OtherADtest.au3"  
ObjCreate("ADODB.Connection"): 0
ObjGet("LDAP://RootDSE"): 0
ObjGet("LDAP:"): 0
ObjCreate("ADODB.Command"): 0
UBound($DCList): 1
I:\Administrators\AutoitScripts\AD_inactive\OtherADtest.au3 (51) : ==> Object referenced outside a "With" statement.:
$objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" ).Value & ">;;serverReferenceBL;Range=0-*;base"
$objCommand.CommandText = "<LDAP://" & $strHostServer & "/" & $objRecordSet.Fields("distinguishedName" )^ ERROR
->09:58:03 AutoIT3.exe ended.rc:1
+>09:58:04 AutoIt3Wrapper Finished
>Exit code: 1   Time: 18.882

[edit to include snapshot of the COM error]

post-7657-1230570234_thumb.jpg

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I found my issue...

Our Active Directory apparently requires authentication, so I added a few .properties lines to the $objConnection area and got it to work.

Global $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
ConsoleWrite('ObjCreate("ADODB.Connection"): ' & @error & @CRLF)
$objConnection.ConnectionString = "Provider=ADsDSOObject"
$objConnection.Properties("User ID") = "DOMAIN\UserID"  ; Administrator Account
$objConnection.Properties("Password") = "Password" ; Associated Password
$objConnection.Properties("Encrypt Password") = 1 ; Just for good measure :)
$objConnection.Open("Active Directory Provider") ; Open connection to AD

Thanks for the help guys.

-Spook

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...