Jump to content
Sign in to follow this  
Webs

AutoIT Array Error

Recommended Posts

Webs

I get the following error message when my script gets to a certain point:

Error message: Array Variable has incorrect number of subscripts or subscript dimension range exceeded.

I have compiled the script to run as an EXE and during the first pass through the first Do loop in the RegEdit function things run just fine. Then for some reason the script attempts to go through the first Do loop a second time. This makes little sense to me since right now there are only 2 values in the Server list text file, the first line is completely blank, and the second line starts the list of servers. To keep things simple I only have one server listed in the file.

So two questions, 1) why does the script go through a second time? 2) when it does loop through a second time, why do I get the error above?

Any help or ideas would be greatly appreciated!

;Read values from server list text file into an array
$aServersMax = _FileReadToArray ( $serverListPath, $serverName )
If @error = 1 Then
    ;Unable to open file, stop script and send email
    $emailSubject = "Registry Key Edit Script: Could not open text file"
    $emailBody0 = "The script could not open the server list text file."
    $emailBody2 = ""
    $emailBody4 = ""
    $emailBody5 = "Location of Error: FileReadtoArray function 1st one"
    SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
    Exit
EndIf

;Read values from managers text file into an array
$aManagersMax = _FileReadToArray ( $managersPath, $managers )
If @error = 1 Then
    ;Unable to open file, stop script and send email
    $emailSubject = "Registry Key Edit Script: Could not open text file"
    $emailBody0 = "The script could not open the server list text file."
    $emailBody2 = ""
    $emailBody4 = ""
    $emailBody5 = "Location of Error: FileReadtoArray function, 2nd one"
    SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
    Exit
EndIf

RegEdit ( $serverName, $managers, $regKeySearchFull, $mainKey, $PermittedManagers, $RFC1156Agent, $ValidCommunities )

MsgBox ( 1, "Out of Function", "End of Script" )

$emailSubject = "Registry Key Change Script: Success!! Registry Updated"
$emailBody0 = "The script successfully updated the registry."
$emailBody2 = ""
$emailBody4 = ""
$emailBody5 = ""
SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
Exit


Func RegEdit ( $aServerName, $aManagers, $regKeySearchPass, $mainKeyPass, $PermittedManagersPass, $RFC1156AgentPass, $ValidCommunitiesPass )

    $keyPathFull = $mainKeyPass & "\" & $regKeySearchPass
    $keyPMFull = $keyPathFull & $PermittedManagersPass
    $keyRFCFull = $keyPathFull & $RFC1156AgentPass
    $keyVCFull = $keyPathFull & $ValidCommunitiesPass
    $element = 2

    Do

        $i = 1
        MsgBox ( 1, "RegEdit Function: Managers For loop", "Made it, value of $element: " & $aServerName[$element] )

        Do              ;loop through values for Permitted Managers

            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyPMFull, $counter, $keyTypeREGSZ, $aManagers[$i] )

            $i = $i + 1

        Until $i = 13

        MsgBox ( 1, "RegEdit Function: key edits", "More RegWrites" )

        ;RFC1156Agent reg keys to edit:
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyRFCFull, "sysContact", $keyTypeREGSZ, "RG Infrastructure" )
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyRFCFull, "sysLocation", $keyTypeREGSZ, "JDPS EW" )

        ;ValidCommunities reg keys to edit:
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "dssb", $keyTypeREGDWORD, "4" )
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "jdpsmon", $keyTypeREGDWORD, "4" )
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "sn0wb@ll", $keyTypeREGDWORD, "4" )

        MsgBox ( 1, "RegEdit Function: End, Next Server will now be processed", "Next Please" )

        $element = $element + 1

    MsgBox ( 1, "RegEdit Function: End", "Done" )

    Until $element = $aServerName[0]

EndFunc

Share this post


Link to post
Share on other sites
SmOke_N

You have hard coded the exit point of the 2nd Do/Until to 13.

If you're throwing the exception there... then change:

Until $i = 13

To

Until $i = $aManagers[0]

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Webs

You have hard coded the exit point of the 2nd Do/Until to 13.

If you're throwing the exception there... then change:

Until $i = 13

To

Until $i = $aManagers[0]

Thanks for your help Sm0ke_N, but I still get the error. It appears to show up as soon as the script reaches the Until of the first Do loop (the last line in the function).

If it helps to clarify, ServerName array has only 2 items in it, a blank line and 1 server name. Managers array has 13 items in it.

Share this post


Link to post
Share on other sites
SmOke_N

And if you clean it up a bit... what happens then?

Func RegEdit ( $aServerName, $aManagers, $regKeySearchPass, $mainKeyPass, $PermittedManagersPass, $RFC1156AgentPass, $ValidCommunitiesPass )

    Local $keyPathFull = $mainKeyPass & "\" & $regKeySearchPass
    Local $keyPMFull = $keyPathFull & $PermittedManagersPass
    Local $keyRFCFull = $keyPathFull & $RFC1156AgentPass
    Local $keyVCFull = $keyPathFull & $ValidCommunitiesPass
; ################
If Not IsArray($aServerName) Then
    MsgBox(16, "Error", "$aServerName is not an array")
    Exit
EndIf
If Not IsArray($aManagers) Then
    MsgBox(16, "Error", "$aManagers is not an array")
    Exit
EndIf
    
; ###############

    For $element = 1 To $aServerName[0]
        If Not $aServerName[$element] Then ContinueLoop
        For $i = 1 To $aManagers[0]
            RegWrite ( "\\" & $aServerName[$element] & "\" & $keyPMFull, $counter, $keyTypeREGSZ, $aManagers[$i] )
        Next
    ;RFC1156Agent reg keys to edit:
        RegWrite ( "\\" & $aServerName[$element] & "\" & $keyRFCFull, "sysContact", $keyTypeREGSZ, "RG Infrastructure" )
        RegWrite ( "\\" & $aServerName[$element] & "\" & $keyRFCFull, "sysLocation", $keyTypeREGSZ, "JDPS EW" )

    ;ValidCommunities reg keys to edit:
        RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "dssb", $keyTypeREGDWORD, "4" )
        RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "jdpsmon", $keyTypeREGDWORD, "4" )
        RegWrite ( "\\" & $aServerName[$element] & "\" & $keyVCFull, "sn0wb@ll", $keyTypeREGDWORD, "4" )
    Next

EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Webs

And if you clean it up a bit... what happens then?

That worked perfect!! I no longer get the error. Thanks a ton for your help. Now I just need to figure out why none of my keys were updated, but I think I can figure that out with some playing around.

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  

×