Jump to content

"Error: Array variable has incorrect number of subscripts..." problem


Recommended Posts

This problem is intermittent, but when the script is ran, it will sometime get the "Error:  Array variable has incorrect number of subscripts or subscript dimension range extended." problem. 

The intent of this script is to determine the currently logged in user while running in the system context when ran through SCCM and then copy the "cacerts" directory to a Program Files path and then two other certs to the actual currently logged in user.  Then if a string doesn't exist in the Java exception.sites file, then add it to the end of that clear text file.

So I "assume" the problem is related to the "StringRegExp" entries, but no idea how to address since the problem is inconsistent.  Any ideas?  Thanks in advance!

 

#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Test.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\DetectionMethod","Test","REG_SZ","Installed")


;Get LastLoggedOnUser value, which is the currently logged in user
$GetCurrentUser = RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI","LastLoggedOnUser")


;Strip domain\ from LastLoggedOnUser value
$before = $GetCurrentUser
$after = StringSplit($before, "\")[2]


FileCopy(@ScriptDir & "\cacerts",@ProgramFilesDir & "\Java\jre1.8.0_172\lib\security\",1)
FileCopy(@ScriptDir & "\sandbox.certs","c:\users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\",1)
FileCopy(@ScriptDir & "\trusted.certs","c:\users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\",1)


While 1
Sleep(1000)
$file = FileOpen("c:\Users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites", 0)
$read = FileRead($file)
If @error = -1 Then
   MsgBox(0, "Focal Point Error", "The file of " & "c:\Users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites" & " appears to be open.  Please close it, so it can be modified for focal point.")
   Exit
Else
    If Not StringRegExp($read,"https://sapportal.corp.test.com/") Then
       FileWriteLine("c:\Users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites","https://sapportal.corp.test.com/" & @CRLF)
    EndIf
    If Not StringRegExp($read,"https://sapportalqa.corp.test.com/") Then
       FileWriteLine("c:\Users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites","https://sapportalqa.corp.test.com/" & @CRLF)
    EndIf
    If Not StringRegExp($read,"https://sapportalstg.corp.test.com") Then
       FileWriteLine("c:\Users\" & $after & "\AppData\LocalLow\Sun\Java\Deployment\security\exception.sites","https://sapportalstg.corp.test.com/" & @CRLF)
    EndIf
Exit
EndIf
FileClose($file)
WEnd

 

Edited by TheCrimsonCrusader
Link to comment
Share on other sites

The only line that could generate this error seems to be this one

$after = StringSplit($before, "\")[2]

if $before don't contain a string formated like [domain]\[username]. You can get the username also using @UserName macro. 

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Try to do it simple:

#NoTrayIcon
#RequireAdmin
#Region
#AutoIt3Wrapper_Icon=Test.ico
#EndRegion

Global $Java_security_path = @HomeDrive & "\users\" & @UserName & "\AppData\LocalLow\Sun\Java\Deployment\security"
Global $file_exception = $Java_security_path & "\exception.sites"
Global $Url_exception = "https://sapportal.corp.test.com/"

FileCopy(@ScriptDir & "\cacerts", @ProgramFilesDir & "\Java\jre1.8.0_172\lib\security\", 1) ;;;;NEED FIX IT - GET JAVA PATH ;;;;;
FileCopy(@ScriptDir & "\sandbox.certs", $Java_security_path & "\sandbox.certs", 1)
FileCopy(@ScriptDir & "\trusted.certs", $Java_security_path & "\trusted.certs", 1)

If Not FileExists($file_exception) Then Exit MsgBox(48, "Error Not Found", "The file " & $file_exception & " !")

Global $read = FileRead($file_exception)
If @error Then
    MsgBox(48, "Focal Point Error", "The file " & $file_exception & " appears to be open." & @CRLF & "Please close it, so it can be modified for focal point.")
    Exit
Else
    If Not StringInStr($read, $Url_exception) Then FileWriteLine($file_exception, $Url_exception)
EndIf

MsgBox(0, "Write Done", "File " & $file_exception & " !")
Exit

 

Regards,
 

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