Page 1 of 3 123>
Topic Options
#155958 - 2006-01-25 08:48 PM Problems with calling array elements in strings...
thepip3r Offline
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
#155959 - 2006-01-25 08:56 PM Re: Problems with calling array elements in strings...
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
The variable $Biosarray[4] is local to the function.
Declare it as a global at the beginning of the script.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#155960 - 2006-01-25 09:12 PM Re: Problems with calling array elements in strings...
thepip3r Offline
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
#155961 - 2006-01-25 09:19 PM Re: Problems with calling array elements in strings...
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Global $BiosArray[4]
and remove the Dim $BiosArray[4] from the function.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#155962 - 2006-01-25 09:24 PM Re: Problems with calling array elements in strings...
thepip3r Offline
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
#155963 - 2006-01-25 09:31 PM Re: Problems with calling array elements in strings...
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I am no good with WMI, so will let someone else help with that part.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#155964 - 2006-01-25 09:32 PM Re: Problems with calling array elements in strings...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Thanx for trying Gargoyle. I do appreciate the help...
Top
#155965 - 2006-01-25 09:50 PM Re: Problems with calling array elements in strings...
thepip3r Offline
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 Offline
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
#155967 - 2006-01-26 01:04 AM Re: Problems with calling array elements in strings...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't get what you are trying to do with ReadLine(). You Open(), ReadLine() the first line, do some shit, ReadLine() the second line but then immediately Close() the files without doing anything more with it.

What error are you getting?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#155968 - 2006-01-26 01:08 AM Re: Problems with calling array elements in strings...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Look up in this thread at post #155588 that will make more sense with what I'm actually trying to do and the error I am getting. I'm trying to loop through a text file of machine names to get their serial number using WMI.
Top
#155969 - 2006-01-26 01:13 AM Re: Problems with calling array elements in strings...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ah, I see there was a loop in your earlier code but now you removeed it. So, where is your code failing?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#155970 - 2006-01-26 01:38 AM Re: Problems with calling array elements in strings...
thepip3r Offline
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
#155971 - 2006-01-26 01:54 AM Re: Problems with calling array elements in strings...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Then probably, ReadLine() is not returning what you and the function expect.

After the line:
$CurrentPC = ReadLine(4)

add the Lines:
'CurrentPC = [' + $CurrentPC + ']' ?
Get $_
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#155972 - 2006-01-26 02:04 AM Re: Problems with calling array elements in strings...
thepip3r Offline
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 Offline
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 Offline
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 Offline
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 ConfirmWMI

http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=114011
 

Top
#155976 - 2006-01-26 02:55 AM Re: Problems with calling array elements in strings...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
I still get the same error with your script NTDOC. It gives me the first computer's BIOS info and then it errors out with that exact same error. I don't get what's going on.. it keeps saying, "Expecting ')'!" and I don't see where another damn parenthesis needs to go!!! It's driving me nuts!

Edit: My original script works too but only for the first one... It seems to be erroring out on ones that aren't contactable... working on throwing the ping() function in it and confirmWMI().


Edited by thepip3r (2006-01-26 03:03 AM)

Top
#155977 - 2006-01-26 03:05 AM Re: Problems with calling array elements in strings...
NTDOC Administrator Offline
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
Page 1 of 3 123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 584 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.079 seconds in which 0.033 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org