#155958 - 2006-01-25 08:48 PM
Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
I'm writing a script to query for the Serial number of machines on our network. I keep getting an error and have narrowed it down to line 16 where I'm calling an array element. I've tried single quotes, double quotes, and no quotes and can't get it to work but the script runs without error when the array element is removed. Can anyone explain that to me? Thank you in advance..Code: Break ON $ = SetOption("WrapAtEOL","ON") $LogFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$LogFile,2) $OpenLogFile = OPEN(5,$OutputFile,5) If $OpenListFile = 0 $CurrentPC = ReadLine(4) If $OpenLogFile = 0 DO ? $CurrentPC $ = WRITELINE(5,"$CurrentPC, ") $MyBIOSInfo = GetBIOSInfo("$CurrentPC") $ = WRITELINE(5, "$BIOSArray[3]" + @CRLF) $CurrentPC = ReadLine(4) UNTIL @ERROR = -1 ENDIF ENDIF CLOSE(4) CLOSE(5) Sleep 5 Function GetBIOSInfo($Computer) Dim $Computer, $WMIService, $BIOSItems, $BIOSName, $BIOSVersion, $SMBIOSVersion Dim $Item, $SerialNumber, $Manufacturer, $BIOSArray[4] ;$Computer = "." $WMIService = GetObject("winmgmts:\\" + $Computer + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $BIOSArray[0]=$BIOSName $BIOSArray[1]=$BIOSVersion $BIOSArray[2]=$SMBIOSVersion $BIOSArray[3]=$SerialNumber $BIOSArray[4]=$Manufacturer $GetBIOSInfo=$BIOSArray EndFunction
Top
#155960 - 2006-01-25 09:12 PM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
Ok, I tried this and still can't get it to work. Any more suggestions?Code: Break ON $ = SetOption("WrapAtEOL","ON") Global $MyBIOSInfo $LogFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$LogFile,2) $OpenLogFile = OPEN(5,$OutputFile,5) If $OpenListFile = 0 $CurrentPC = ReadLine(4) If $OpenLogFile = 0 DO ? $CurrentPC $MyBIOSInfo = GetBIOSInfo("$CurrentPC") $ = WRITELINE(5,"$CurrentPC, ") $ = WRITELINE(5, $MyBIOSInfo[3] + @CRLF) $CurrentPC = ReadLine(4) UNTIL @ERROR = -1 ENDIF ENDIF CLOSE(4) CLOSE(5) Sleep 5 Function GetBIOSInfo($Computer) Dim $Computer, $WMIService, $BIOSItems, $BIOSName, $BIOSVersion, $SMBIOSVersion Dim $Item, $SerialNumber, $Manufacturer, $BIOSArray[4] ;$Computer = "." $WMIService = GetObject("winmgmts:\\" + $Computer + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $BIOSArray[0]=$BIOSName $BIOSArray[1]=$BIOSVersion $BIOSArray[2]=$SMBIOSVersion $BIOSArray[3]=$SerialNumber $BIOSArray[4]=$Manufacturer $GetBIOSInfo=$BIOSArray EndFunction
Top
#155962 - 2006-01-25 09:24 PM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
Here is what I did:Code: Break ON $ = SetOption("WrapAtEOL","ON") Global $BIOSArray[4] $LogFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$LogFile,2) $OpenLogFile = OPEN(5,$OutputFile,5) If $OpenListFile = 0 $CurrentPC = ReadLine(4) If $OpenLogFile = 0 DO ? $CurrentPC $MyBIOSInfo = GetBIOSInfo("$CurrentPC") $ = WRITELINE(5,"$CurrentPC, ") $ = WRITELINE(5, $MyBIOSInfo[3] + @CRLF) $CurrentPC = ReadLine(4) UNTIL @ERROR = -1 ENDIF ENDIF CLOSE(4) CLOSE(5) Sleep 5 Function GetBIOSInfo($Computer) Dim $Computer, $WMIService, $BIOSItems, $BIOSName, $BIOSVersion, $SMBIOSVersion Dim $Item, $SerialNumber, $Manufacturer ;$Computer = "." $WMIService = GetObject("winmgmts:\\" + $Computer + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $BIOSArray[0]=$BIOSName $BIOSArray[1]=$BIOSVersion $BIOSArray[2]=$SMBIOSVersion $BIOSArray[3]=$SerialNumber $BIOSArray[4]=$Manufacturer $GetBIOSInfo=$BIOSArray EndFunction I still get the same error: ERROR : expected ')'! Script: C:\Docs and setting\ blabh blah\serial.kix Line : 36
Top
#155965 - 2006-01-25 09:50 PM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
Ok, I pulled the function out in trying to troubleshoot and I still get the same error but now on line 17...Code: Break ON $ = SetOption("WrapAtEOL","ON") $LogFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$LogFile,2) $OpenLogFile = OPEN(5,$OutputFile,5) If $OpenListFile = 0 $CurrentPC = ReadLine(4) If $OpenLogFile = 0 DO ? $CurrentPC $WMIService = GetObject("winmgmts:\\" + $CurrentPC + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $ = WRITELINE(5,"$CurrentPC, ") $ = WRITELINE(5, $SerialNumber + @CRLF) $CurrentPC = ReadLine(4) UNTIL @ERROR = -1 ENDIF ENDIF CLOSE(4) CLOSE(5) Sleep 5 Any thoughts now?
Top
#155966 - 2006-01-25 11:49 PM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
Rewritten again!!! If I leave it this way, it runs against the target computer fine... When I comment that $currentPC out and uncomment the other two for the loop, I get the error; am I calling ReadLine() incorrectly??? PLEASE HELP!!!!Code: Break ON $ = SetOption("WrapAtEOL","ON") Global $MyBIOSInfo $ListFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$ListFile,2) $OpenOutputFile = OPEN(5,$OutputFile,5) $CurrentPC = "ecs-scbna-cjdw" If $OpenListFile = 0 ;$CurrentPC = ReadLine(4) If $OpenOutputFile = 0 $MyBIOSInfo = GetBIOSInfo($CurrentPC) ? $MyBIOSInfo[1] + @CRLF ? $MyBIOSInfo[2] + @CRLF ? $MyBIOSInfo[3] + @CRLF ? $MyBIOSInfo[4] + @CRLF ;$CurrentPC = ReadLine(4) Endif Endif Close(4) Close(5) sleep 5 Function GetBIOSInfo($Computer) Dim $Computer, $WMIService, $BIOSItems, $BIOSName, $BIOSVersion, $SMBIOSVersion Dim $Item, $SerialNumber, $Manufacturer, $BIOSArray[4] ;$Computer = "." $WMIService = GetObject("winmgmts:\\" + $Computer + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $BIOSArray[0]=$BIOSName $BIOSArray[1]=$BIOSVersion $BIOSArray[2]=$SMBIOSVersion $BIOSArray[3]=$SerialNumber $BIOSArray[4]=$Manufacturer $GetBIOSInfo=$BIOSArray EndFunction
Edited by thepip3r (2006-01-25 11:50 PM )
Top
#155970 - 2006-01-26 01:38 AM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
For the code in #155588, it says it's failing on a missing ) maybe??? This is the error by Kix before it closes:Code: ERROR : expected ')'! Script: C:\Docs and setting\ blabh blah\serial.kix Line : 36 ...and this indicates the function but I know it's not a problem with the function because it works fine by itself when you pass single computer names to it. Thats why in my latest code post, I had taken the loop and stuff out; trying to figure out where the function was failing and it turns out that for some reason, the ReadLine() is what causes the error. When it's uncommented, it doesn't error out, when it's commented, the script runs fine. FYI - I'm running KiX 2010 executable...
Top
#155972 - 2006-01-26 02:04 AM
Re: Problems with calling array elements in strings...
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
The script returned this: "CurrentPC = [pccomputername]" And now it's acting like it's locked up and doesn't close unless I close it manually. Here is what the code looks like:Code: Break ON $ = SetOption("WrapAtEOL","ON") $LogFile = "C:\computer_list.txt" $OutputFile = "C:\output_file.txt" $OpenListFile = OPEN(4,$LogFile,2) $OpenLogFile = OPEN(5,$OutputFile,5) If $OpenListFile = 0 $CurrentPC = ReadLine(4) 'CurrentPC = [' + $CurrentPC + ']' ? Get $_ If $OpenLogFile = 0 DO ? $CurrentPC $WMIService = GetObject("winmgmts:\\" + $CurrentPC + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery( "Select * from Win32_BIOS where PrimaryBIOS = true", , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim($Item.Name) $BIOSVersion = Trim($Item.Version) $SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion) $SerialNumber = Trim($Item.SerialNumber) $Manufacturer = Trim($Item.Manufacturer) Next $ = WRITELINE(5,"$CurrentPC, ") $ = WRITELINE(5, $SerialNumber + @CRLF) $CurrentPC = ReadLine(4) UNTIL @ERROR = -1 ENDIF ENDIF CLOSE(4) CLOSE(5) Sleep 5
Top
#155973 - 2006-01-26 02:11 AM
Re: Problems with calling array elements in strings...
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Here, give this code snippet a try. Break On Dim $SO $SO =SetOption ('Explicit' ,'On' )$SO =SetOption ('NoVarsInStrings' ,'On' )$SO =SetOption ('NoMacrosInStrings' ,'On' ) Dim $sComputers ,$sComputer ,$Details ,$Detail $sComputers = ReadFile (@ScriptDir +'\' +'computer_list.txt' )For Each $sComputer In $sComputers If $sComputer $Details = GetBIOSInfo ($sComputer ) ? '*** ' + $sComputer + ' ***' ? '*********************' ? For Each $Detail In $Details $Detail ? Next EndIf Next Exit @ERROR Function GetBIOSInfo(optional $sComputer ) Dim $WMIService ,$BIOSItems ,$BIOSName ,$BIOSVersion ,$SMBIOSVersion Dim $Item , $SerialNumber , $Manufacturer , $BIOSArray [4 ] $sComputer =IIf (Not $sComputer ,'' ,'\\' +Join (Split ($sComputer ,'\' ),'' ,3 )+'\' ) $WMIService = GetObject ("winmgmts:{impersonationLevel=impersonate}!" +$sComputer +'root\cimv2' ) $BIOSItems = $WMIService.ExecQuery ("Select * from Win32_BIOS where PrimaryBIOS = true" , , 48 ) For Each $Item in $BIOSItems $BIOSName = Trim ($Item.Name ) $BIOSVersion = Trim ($Item.Version ) $SMBIOSVersion = Trim ($Item.SMBIOSBIOSVersion ) $SerialNumber = Trim ($Item.SerialNumber ) $Manufacturer = Trim ($Item.Manufacturer ) Next $BIOSArray [0 ]=$BIOSName $BIOSArray [1 ]=$BIOSVersion $BIOSArray [2 ]=$SMBIOSVersion $BIOSArray [3 ]=$SerialNumber $BIOSArray [4 ]=$Manufacturer $GetBIOSInfo =$BIOSArray EndFunction Function ReadFile($file ) Dim $lf , $f , $_ , $t $lf =CHR (10 ) $f =FreeFileHandle $_ =Open ($f ,$file ) If @ERROR Exit @ERROR EndIf Do $t =$t +$lf +ReadLine ($f ) Until @ERROR $_ =Close ($f ) $ReadFile =Split (SubStr ($t ,2 ),$lf )EndFunction
Top
#155974 - 2006-01-26 02:36 AM
Re: Problems with calling array elements in strings...
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Don't forget though that you may want to PING them first and also check that WMI is working before running it. There is a ConfirmWMI() UDF for that in the UDF forum. and Les has not posted this as a UDF yet, but works fairly well for pinging the systems.Code: Function Ping($PC) Shell'%comspec% /c ping -n 1 '+$PC+' >nul' $Ping = NOT @error EndFunction
Edited by NTDOC (2006-01-26 02:37 AM )
Top
#155975 - 2006-01-26 02:42 AM
Re: Problems with calling array elements in strings...
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Works like this. Code: Dim $RC $RC = Ping('somesystem') If $RC 'pc online' Else 'pc offline' EndIf Function Ping($PC) Shell'%comspec% /c ping -n 1 '+$PC+' >nul' $Ping = NOT @ERROR EndFunction and here is the link to ConfirmWMIhttp://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=114011
Top
#155977 - 2006-01-26 03:05 AM
Re: Problems with calling array elements in strings...
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
My guess... No WMI or broken WMI on the remote system or the system is not available period. That is why I said above you should also add some more to the code for a production run. Try adding the PING UDF and this ConfirmWMI UDF to the code or at least testint the WMI with this code on the one that breaks. Also, what version of KiXtart are you using? Function ConfirmWMI(optional $sComputer ) Dim $objWMIService ,$objWMISetting ,$colWMISettings $sComputer =IIf (Not $sComputer ,'' ,'\\' +Join (Split ($sComputer ,'\' ),'' ,3 )+'\' ) $objWMIService = GetObject ("winmgmts:{impersonationLevel=impersonate}!" +$sComputer +'root\cimv2' ) If @ERROR $ConfirmWMI = Val ("&" +Right (DecToHex (@ERROR ),4 )) Exit $ConfirmWMI EndIf $colWMISettings = $objWMIService.ExecQuery ("Select * from Win32_WMISetting" ) For Each $objWMISetting In $colWMISettings $ConfirmWMI = $objWMISetting.BuildVersion Next Exit $ConfirmWMI EndFunction
Top
Moderator: Arend_ , Allen , Jochen , Radimus , Glenn Barnas , ShaneEP , Ruud van Velsen , Mart
0 registered
and 584 anonymous users online.