mojed893 Posted September 2, 2011 Posted September 2, 2011 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. #RequireAdminIf @OSArch = "X64" Then Local $stOldVal = DllStructCreate("dword") DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal))EndIf ;Configure PowerShellRunWait('cmd /c powershell.exe set-executionpolicy remotesigned',"",@SW_HIDE) ;Remove any existing DeploymentShareRunWait('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 shareDirCreate("c:\DeploymentShare")RunWait('cmd /c powershell.exe -file ' & $cdsFileTemp,"",@SW_HIDE)FileDelete($cdsFileTemp) ;Import the OSRunWait('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 shareDirCreate("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 guidRunWait('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 disksRunWait('cmd /c powershell.exe -command ' & @ScriptDir & '\UpdateDeploymentShare.ps1') ;Create the media, configure and update themDirCreate("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 ISOShellExecuteWait("C:\deploymentshare\media") If @OSArch = "X64" Then Local $stOldVal = DllStructCreate("dword")DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal))EndIf
BrewManNH Posted September 2, 2011 Posted September 2, 2011 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 GudeHow to ask questions the smart way! Reveal hidden contents 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
mojed893 Posted September 2, 2011 Author Posted September 2, 2011 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
BrewManNH Posted September 2, 2011 Posted September 2, 2011 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 GudeHow to ask questions the smart way! Reveal hidden contents 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
BillC Posted August 18, 2014 Posted August 18, 2014 I'm having this problem with the same script from Panos Macheras at http://blogs.technet.com/b/panosm/archive/2011/07/07/windows-7-steadystate-solution-simplified.aspx. Were you able to find out where the error was in the SETUP.au3 script?
Moderators Melba23 Posted August 19, 2014 Moderators Posted August 19, 2014 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 Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BillC Posted August 19, 2014 Posted August 19, 2014 Thank you for clarifying. It wasn't clear to me that the issue had actually been resolved.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now