Syed23 Posted July 18, 2011 Posted July 18, 2011 Hi All, I have created a tool to check the installed core application details on machine. Previously it was working fine. But i have added new function to my code and i am facing the error message "Error: Subscript used with non-Array Variable". on the below loop. can some one help me on this? If $Excel = 1 Then $numberOfChannels = _XMLGetNodeCount("/root/Office") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office[" & $s & "]/Name") $RegKey = _XMLGetChildText("/root/Office[" & $s & "]/Location") _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") Else $numberOfChannels = _XMLGetNodeCount("/root/Office1") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office1[" & $s & "]/Name") $RegKey = _XMLGetChildText("/root/Office1[" & $s & "]/Location") _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") EndIf Note: For your reference i have attached the newly added code below too. Please let me know if you need my complete code! expandcollapse popupIf $win7cust1 = 1 Then MsgBox(0, $Title, "Inside the Win cust") $source = "C:\Temp\AutoIT Files\W7-Custom.xml" FileCopy($source, $location, 1) If FileExists($location & "\W7-Custom.xml") Then $file = _XMLFileOpen($location & "\W7-Custom.xml") $xmlname = FileGetLongName($location & "\W7-Custom.xml") $numberOfChannels = _XMLGetNodeCount("/root/Registry") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $numberOfChannels & " of applications are there to check") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $xmlname & " is the XML we are using") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Registry[" & $s & "]/Comment") $RegKey = _XMLGetChildText("/root/Registry[" & $s & "]/FilePath") $KeyValue = _XMLGetChildText("/root/Registry[" & $s & "]/Key") $ValueDataExp = _XMLGetChildText("/root/Registry[" & $s & "]/KeyValue") _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/File") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/File[" & $s & "]/Comment") $RegKey = _XMLGetChildText("/root/File[" & $s & "]/FilePath") _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/RegistryExist") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Comment") $RegKey = FileGetLongName(@HomeShare) & _XMLGetChildText("/root/RegistryExist[" & $s & "]/FilePath") $KeyValue = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Key") $ValueDataExp = _XMLGetChildText("/root/RegistryExist[" & $s & "]/KeyValue") _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next ; $Comment = "Check for WInfo Tool Executable" ; $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Utils\WInfoTool.exe" ; _ReportFileExists($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5" _ReportFileExists4($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5\ActiveSetup.EXE" _ReportFileExists($Comment, $RegKey) $Comment = "Removing DomainCheck.VBS File" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Script\DomainCheck.vbs" _ReportFileExists5($Comment, $RegKey) $Comment = "Windows 7 installation User Wallpaper Removed ?" $RegKey = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper") _ReportFileExists($Comment, $RegKey) $Comment = "TPM PIN Status" $TPM = Pin($compname) _ReportFileExists6($TPM, $Comment) Else _FileWriteLog($Logpath, "INFO > ERROR >" & "W7-Customisation.xml is not found on " & $location & ". The Problem may be it code was unable to copy teh XML file from the source location.") _ExtMsgBox(64, "&OK", $Title, "Could not find the XML on " & $xmlname & ". Probelm may happened during the file copy process.For more information check the log file!") Call("Process") EndIf EndIf $Comment = "Version of Windows 7 Service Pack" $OSSP = @OSServicePack _ReportFileExists2($OSSP, $Comment) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment, 60, 50, 340, 32) GUISetFont(9, 350, $font1) Call("Result") Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
jaberwacky Posted July 18, 2011 Posted July 18, 2011 (edited) Try this code and report the results. expandcollapse popup#include <Array.au3> If $Excel = 1 Then $numberOfChannels = _XMLGetNodeCount("/root/Office") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office[" & $s & "]/Name") If IsArray($Comment) Then _arrayDisplay($Comment) Else MsgBox(16, "Error", "$Comment is not an array") EndIf $RegKey = _XMLGetChildText("/root/Office[" & $s & "]/Location") If IsArray($RegKey) Then _arrayDisplay($RegKey) Else MsgBox(16, "Error", "$RegKey is not an array") EndIf _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") Else $numberOfChannels = _XMLGetNodeCount("/root/Office1") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office1[" & $s & "]/Name") If IsArray($Comment) Then _arrayDisplay($Comment) Else MsgBox(16, "Error", "$Comment is not an array") EndIf $RegKey = _XMLGetChildText("/root/Office1[" & $s & "]/Location") If IsArray($RegKey) Then _arrayDisplay($RegKey) Else MsgBox(16, "Error", "$Regkey is not an array") EndIf _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") EndIf Edited July 18, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Syed23 Posted July 18, 2011 Author Posted July 18, 2011 (edited) Try this code and report the results. expandcollapse popup#include <Array.au3> If $Excel = 1 Then $numberOfChannels = _XMLGetNodeCount("/root/Office") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office[" & $s & "]/Name") If IsArray($Comment) Then _arrayDisplay($Comment) Else MsgBox(16, "Error", "$Comment is not an array") EndIf $RegKey = _XMLGetChildText("/root/Office[" & $s & "]/Location") If IsArray($RegKey) Then _arrayDisplay($RegKey) Else MsgBox(16, "Error", "$RegKey is not an array") EndIf _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") Else $numberOfChannels = _XMLGetNodeCount("/root/Office1") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office1[" & $s & "]/Name") If IsArray($Comment) Then _arrayDisplay($Comment) Else MsgBox(16, "Error", "$Comment is not an array") EndIf $RegKey = _XMLGetChildText("/root/Office1[" & $s & "]/Location") If IsArray($RegKey) Then _arrayDisplay($RegKey) Else MsgBox(16, "Error", "$Regkey is not an array") EndIf _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") EndIf Yeah... This works fine! It displays me the Comments variables... what i feel is the problem occurs on my newly added function.... i could feel that... but i don't know where it causes. Edited July 18, 2011 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
jaberwacky Posted July 18, 2011 Posted July 18, 2011 SciTE doesn't indicate the line where the error occurs? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Syed23 Posted July 18, 2011 Author Posted July 18, 2011 (edited) SciTE doesn't indicate the line where the error occurs? No! Durig the compilation and also i tried executing the code from SciTe but it not indicates the line where i get the error message. Then i added "Obfuscate" and compiled the script and executed the tool, the error message shows on the below part. . The thing is this is not the line i added newly. I am using this line for such a long time without any issue If $Excel = 1 Then $numberOfChannels = _XMLGetNodeCount("/root/Office") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Office[" & $s & "]/Name") $RegKey = _XMLGetChildText("/root/Office[" & $s & "]/Location") _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next Call("progress") Edited July 18, 2011 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
jaberwacky Posted July 18, 2011 Posted July 18, 2011 (edited) Ok well, all that error message means is that when you've tried to access an element of a variable that is not an array or you're trying to access an element that doesn't exist. Go through your newly added code and add those error checks that I added to your code previously. I did it for you:expandcollapse popupIf $win7cust1 = 1 Then MsgBox(0, $Title, "Inside the Win cust") $source = "C:\Temp\AutoIT Files\W7-Custom.xml" FileCopy($source, $location, 1) If FileExists($location & "\W7-Custom.xml") Then $file = _XMLFileOpen($location & "\W7-Custom.xml") $xmlname = FileGetLongName($location & "\W7-Custom.xml") $numberOfChannels = _XMLGetNodeCount("/root/Registry") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $numberOfChannels & " of applications are there to check") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $xmlname & " is the XML we are using") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Registry[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = _XMLGetChildText("/root/Registry[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $KeyValue = _XMLGetChildText("/root/Registry[" & $s & "]/Key") If Not IsArray($KeyValue) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $ValueDataExp = _XMLGetChildText("/root/Registry[" & $s & "]/KeyValue") If Not IsArray($ValueDataExp) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/File") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/File[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = _XMLGetChildText("/root/File[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/RegistryExist") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = FileGetLongName(@HomeShare) & _XMLGetChildText("/root/RegistryExist[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $KeyValue = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Key") If Not IsArray($KeyValue) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $ValueDataExp = _XMLGetChildText("/root/RegistryExist[" & $s & "]/KeyValue") If Not IsArray($ValueDataExp) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next ; $Comment = "Check for WInfo Tool Executable" ; $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Utils\WInfoTool.exe" ; _ReportFileExists($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5" _ReportFileExists4($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5\ActiveSetup.EXE" _ReportFileExists($Comment, $RegKey) $Comment = "Removing DomainCheck.VBS File" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Script\DomainCheck.vbs" _ReportFileExists5($Comment, $RegKey) $Comment = "Windows 7 installation User Wallpaper Removed ?" $RegKey = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper") _ReportFileExists($Comment, $RegKey) $Comment = "TPM PIN Status" $TPM = Pin($compname) _ReportFileExists6($TPM, $Comment) Else _FileWriteLog($Logpath, "INFO > ERROR >" & "W7-Customisation.xml is not found on " & $location & ". The Problem may be it code was unable to copy teh XML file from the source location.") _ExtMsgBox(64, "&OK", $Title, "Could not find the XML on " & $xmlname & ". Probelm may happened during the file copy process.For more information check the log file!") Call("Process") EndIf EndIf $Comment = "Version of Windows 7 Service Pack" $OSSP = @OSServicePack _ReportFileExists2($OSSP, $Comment) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment, 60, 50, 340, 32) GUISetFont(9, 350, $font1) Call("Result") Edited July 18, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Syed23 Posted July 18, 2011 Author Posted July 18, 2011 Ok well, all that error message means is that when you've tried to access an element of a variable that is not an array or you're trying to access an element that doesn't exist. Go through your newly added code and add those error checks that I added to your code previously. I did it for you: expandcollapse popupIf $win7cust1 = 1 Then MsgBox(0, $Title, "Inside the Win cust") $source = "C:\Temp\AutoIT Files\W7-Custom.xml" FileCopy($source, $location, 1) If FileExists($location & "\W7-Custom.xml") Then $file = _XMLFileOpen($location & "\W7-Custom.xml") $xmlname = FileGetLongName($location & "\W7-Custom.xml") $numberOfChannels = _XMLGetNodeCount("/root/Registry") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $numberOfChannels & " of applications are there to check") _FileWriteLog($Logpath, "INFO > Windows 7-64 bit>" & $xmlname & " is the XML we are using") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/Registry[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = _XMLGetChildText("/root/Registry[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $KeyValue = _XMLGetChildText("/root/Registry[" & $s & "]/Key") If Not IsArray($KeyValue) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $ValueDataExp = _XMLGetChildText("/root/Registry[" & $s & "]/KeyValue") If Not IsArray($ValueDataExp) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/File") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/File[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = _XMLGetChildText("/root/File[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportFileExists($Comment[1], $RegKey[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next $numberOfChannels = _XMLGetNodeCount("/root/RegistryExist") For $s = 1 To $numberOfChannels Step +1 $Comment = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Comment") If Not IsArray($Comment) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $RegKey = FileGetLongName(@HomeShare) & _XMLGetChildText("/root/RegistryExist[" & $s & "]/FilePath") If Not IsArray($RegKey) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $KeyValue = _XMLGetChildText("/root/RegistryExist[" & $s & "]/Key") If Not IsArray($KeyValue) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) $ValueDataExp = _XMLGetChildText("/root/RegistryExist[" & $s & "]/KeyValue") If Not IsArray($ValueDataExp) Then MsgBox(16, "Error", "Script Line: " & @ScriptLineNumber - 1) _ReportRegValueData($Comment[1], $RegKey[1], $KeyValue[1], $ValueDataExp[1]) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment[1], 60, 50, 340, 32) GUISetFont(9, 350, $font1) Next ; $Comment = "Check for WInfo Tool Executable" ; $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Utils\WInfoTool.exe" ; _ReportFileExists($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5" _ReportFileExists4($Comment, $RegKey) $Comment = "N04000B5 directory exists under TPKG Folder" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Tpkgs\N04000B5\ActiveSetup.EXE" _ReportFileExists($Comment, $RegKey) $Comment = "Removing DomainCheck.VBS File" $RegKey = @ProgramFilesDir & "\Enterprise Desktop\Script\DomainCheck.vbs" _ReportFileExists5($Comment, $RegKey) $Comment = "Windows 7 installation User Wallpaper Removed ?" $RegKey = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper") _ReportFileExists($Comment, $RegKey) $Comment = "TPM PIN Status" $TPM = Pin($compname) _ReportFileExists6($TPM, $Comment) Else _FileWriteLog($Logpath, "INFO > ERROR >" & "W7-Customisation.xml is not found on " & $location & ". The Problem may be it code was unable to copy teh XML file from the source location.") _ExtMsgBox(64, "&OK", $Title, "Could not find the XML on " & $xmlname & ". Probelm may happened during the file copy process.For more information check the log file!") Call("Process") EndIf EndIf $Comment = "Version of Windows 7 Service Pack" $OSSP = @OSServicePack _ReportFileExists2($OSSP, $Comment) $Label2 = GUICtrlCreateLabel("Processing= " & $Comment, 60, 50, 340, 32) GUISetFont(9, 350, $font1) Call("Result") Thanks a lot LaCastiglione! The way you helped me to sort my steps to find out the issue and where it fails. Now i fixed the issue again the tool started working Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
jaberwacky Posted July 18, 2011 Posted July 18, 2011 Glad I could help. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
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