Page 3 of 3 <123
Topic Options
#155998 - 2006-01-27 01:41 AM Re: Problems with calling array elements in strings...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Okay I found the error. I coded it incorrectly for the WMI check in the main script. I was doing an If $WMIOkay then assumed WMI was okay and moved on. What can happen is that you can get an error and it would then return and fill that var with the error code which in affect would say that everything was okay and then move on to the next section of the script where it would then get another error trying to query the remote system and perform an abnormal end to the script.

I've modified the code now to check for a specific version and if found continue. If the version is older or an error occurs then it should report that and still keep going with the other computers in the list. I've also modified it to use UPPERCASE names for the computers.

I also updated the GetBIOSInfo UDF so that it would cleanly exit if there was an error as well and not cause the script to abonormally end.


Give this a try and let us know how it works out please.


Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $sComputers,$sComputer,$Details,$Detail
Dim $Alive,$WMIOkay,$CleanUp
$sComputers = ReadFile(@ScriptDir+'\'+'computer_list.txt')
For Each $sComputer In $sComputers
$sComputer = UCase(Trim($sComputer))
If $sComputer
$Alive = Ping($sComputer)
If $Alive
$WMIOkay = ConfirmWMI($sComputer)
If $WMIOkay > '1085'
$Details = GetBIOSInfo($sComputer)
For Each $Detail In $Details
If $Detail
'BIOS for ' +$sComputer +': ' + $Detail ?
EndIf
Next
Else
'WMI error on ' + $sComputer + ' ::Error results: ' +@ERROR + ' ' +@SERROR ?
EndIf
EndIf
EndIf
??
Next

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')
If @ERROR $GetBIOSInfo = Val('&'+Right(DecToHex(@ERROR),4)) Exit $GetBIOSInfo EndIf
$BIOSItems = $WMIService.ExecQuery('Select * from Win32_BIOS where PrimaryBIOS = true',,48)
For Each $Item in $BIOSItems
If $Item
$BIOSName = Trim($Item.Name)
$BIOSVersion = Trim($Item.Version)
$SMBIOSVersion = Trim($Item.SMBIOSBIOSVersion)
$SerialNumber = Trim($Item.SerialNumber)
$Manufacturer = Trim($Item.Manufacturer)
EndIf
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

Function Ping($sComputer)
Shell'%comspec% /c ping -n 1 '+$sComputer+' >nul'
$Ping = NOT @ERROR
EndFunction

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
#155999 - 2006-01-27 01:58 AM Re: Problems with calling array elements in strings...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Worked great. I let it run through the whole script this time too. It actually reports the access is denied for those machines where that is the case. Thanx so much for the continued assistance NTDOC.
Top
#156000 - 2006-01-27 02:04 AM Re: Problems with calling array elements in strings...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
You're quite welcome. Glad I could help.
 

Top
Page 3 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 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.051 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

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