Sign in to follow this  
Followers 0
mojed893

Help with Subscript used with non-Array Variable

7 posts in this topic

Hi Everyone,

I'm completely new to using AutoIT and scripting in general so pardon my ineptitude. I am trying to get a pilot program running for the small public library that I work for. It involves running an AutoIT script, but when I run it I receive the following error:

Line 37 (File: C:\SteadyState\SteatdyWinSteadyState1.0\Setup.exe)

Error: Subscript used with non-Array variable.

I am pasting the script that should be running below and bolding line 37 in the hopes that someone might be able to help me get this running correctly. Thanks for you time and taking a moment to look over this!

Omar M.

#RequireAdmin

If @OSArch = "X64" Then

Local $stOldVal = DllStructCreate("dword")

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal))

EndIf

;Configure PowerShell

RunWait('cmd /c powershell.exe set-executionpolicy remotesigned',"",@SW_HIDE)

;Remove any existing DeploymentShare

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\RemoveDeploymentShare.ps1')

DirRemove("C:\DeploymentShare", 1)

;Insert the computername in CreateDeploymentShare.ps1

$cdsFile = @ScriptDir & '\CreateDeploymentShare.ps1'

$cdsFileTemp = @ScriptDir & '\CreateDeploymentShareTemp.ps1'

$cdsText = FileRead($cdsFile, FileGetSize($cdsFile))

$cdsText = StringReplace($cdsText, "localhost", @ComputerName)

FileWrite($cdsFileTemp, $cdsText)

;Execute Powershell to create the deployment share

DirCreate("c:\DeploymentShare")

RunWait('cmd /c powershell.exe -file ' & $cdsFileTemp,"",@SW_HIDE)

FileDelete($cdsFileTemp)

;Import the OS

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\ImportOS.ps1')

;Rename entry to Windows7.wim

;Also read the OS guid to guidOSText[0]

$osFile = "c:\DeploymentShare\Control\OperatingSystems.xml"

$osFileTemp = "c:\DeploymentShare\Control\OperatingSystemsTemp.xml"

$osText = FileRead($osFile, FileGetSize($osFile))

$guidOSText = StringRegExp($osText, "{.*}", 1)

$osText = StringRegExpReplace($osText, "Name.*/Name", "Name>Windows7.wim</Name")

FileWrite($osFileTemp, $osText)

FileDelete($osFile)

FileCopy($osFileTemp, $osFile)

FileDelete($osFileTemp)

;Configure the deployment share

DirCreate("c:\DeploymentShare\$OEM$\$$\System")

FileCopy(@ScriptDir & "\BootScriptSteadyState.exe", "c:\DeploymentShare\$OEM$\$$\System")

FileCopy(@ScriptDir & "\ConfigureSteadyState.exe", "c:\DeploymentShare\$OEM$\$$\System")

FileCopy(@ScriptDir & "\ZTIDiskpartVHD.wsf", "c:\DeploymentShare\Scripts")

FileCopy(@ScriptDir & "\background.bmp", "c:\DeploymentShare\Scripts")

;FileCopy(@ScriptDir & "\TaskSequences.xml", "c:\DeploymentShare\Control", 1)

;Create a new Task Sequence called STEADYSTATE

;Then replace its file and finally correct the os guid

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\CreateTaskSequence.ps1')

FileCopy(@ScriptDir & "\ts.xml", "C:\DeploymentShare\Control\STEADYSTATE", 1)

$tsFile = "c:\DeploymentShare\Control\STEADYSTATE\ts.xml"

$tsFileTemp = "c:\DeploymentShare\Control\STEADYSTATE\tsTemp.xml"

$tsText = FileRead($tsFile, FileGetSize($tsFile))

$tsText = StringRegExpReplace($tsText, "{.*}", $guidOSText[0])

FileWrite($tsFileTemp, $tsText)

FileDelete($tsFile)

FileCopy($tsFileTemp, $tsFile)

FileDelete($tsFileTemp)

;Configure Bootstrap.ini and CustomSettings.ini

$bFile = @ScriptDir & '\BootstrapLocalhost.ini'

$bFileTemp = @ScriptDir & '\Bootstrap.ini'

$bText = FileRead($bFile, FileGetSize($bFile))

$bText = StringReplace($bText, "localhost", @ComputerName)

FileWrite($bFileTemp, $bText)

FileCopy($bFileTemp, "C:\DeploymentShare\Control", 1)

FileDelete($bFileTemp)

FileCopy(@ScriptDir & "\CustomSettings.ini", "C:\DeploymentShare\Control", 1)

;Update the Deployment Share to create the boot disks

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\UpdateDeploymentShare.ps1')

;Create the media, configure and update them

DirCreate("C:\DeploymentShare\Media")

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\CreateMedia.ps1')

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\GenerateMedia.ps1')

FileCopy($bFileTemp, "C:\DeploymentShare\Media\Content\Deploy\Control", 1)

FileCopy(@ScriptDir & "\BootstrapMedia.ini", @ScriptDir & "\Bootstrap.ini")

FileCopy(@ScriptDir & "\Bootstrap.ini", "C:\DeploymentShare\Media\Content\Deploy\Control", 1)

FileCopy(@ScriptDir & "\CustomSettings.ini", "C:\DeploymentShare\Media\Content\Deploy\Control", 1)

FileCopy(@ScriptDir & "\Settings.xml", "C:\DeploymentShare\Media\Content\Deploy\Control", 1)

RunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\GenerateMedia.ps1')

;Open the folder with the ISO

ShellExecuteWait("C:\deploymentshare\media")

If @OSArch = "X64" Then

Local $stOldVal = DllStructCreate("dword")

DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal))

EndIf

Share this post


Link to post
Share on other sites



I would tend to think your problem lies with this line:

$tsText = StringRegExpReplace($tsText, "{.*}", $guidOSText[0])

Due to the fact it's the only place that you use an array in your script. You can't go by the line number shown when it's compiled, it will rarely correspond to the same line number in your script. StringRegExp without a flag to tell it otherwise, returns a 1 or 0 if it finds or doesn't find the pattern in the string it doesn't return an array. You would need the flag to be set to any number other than zero or no flag to get an array.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi BrewMan,

Thanks for the reply. I don't really understand how I would go about changing it. Would I change the [0] to any other number to return an array or do I have to change that line to something else entirely? What this is supposed to do is create and ISO that makes a VHD so we can secure our computers using VHD differencing. I've been struggling with it for a while and its a project that someone did out of good will to help out public libraries and institutions that had to move away from a microsoft technology that used to keep our machines secure. Again, I'm a total noob when it comes to scripting and programming so I apologize if I am wasting your time or making you do extra work to help me out.

Omar

Share this post


Link to post
Share on other sites

Your code here:

$osText = FileRead($osFile, FileGetSize($osFile))
$guidOSText = StringRegExp($osText, "{.*}", 1)

is what is supposed to return the array to $guidOSText, but if it doesn't find the text in the string $osText,it returns nothing. I don't know what's in the file you're reading so I can't say for sure why it isn't working.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BillC,

The likely problem area was described quite clearly by BrewManNH - the RegEx is almost certainly not returning an array and so the script fails when you try to access an element of this non-array variable later in the script. You need to add code to check if this is the case and deal with it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you for clarifying.  It wasn't clear to me that the issue had actually been resolved.

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  
Followers 0