#155979 - 2006-01-2603:12 AMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Again though for a production script where you would probably be doing more logging you'd want some more code in there for @ERROR results and on what system it failed, etc.. and then log that to a report.
I get the same result adding those two functions in, it just comes back immediately now instead of lagging out for 15 secs like the old script did. Here's what it looks like:
1. I'm running version 2010 or 4.51 as the executable reads 2. My script works for the first computer, then it goes to the second one and errors out...
Code:
Break ON $ = SetOption("WrapAtEOL","ON") Global $BIOSArray[4]
If $OpenListFile = 0 $CurrentPC = ReadLine(4) If $OpenLogFile = 0 DO ? $CurrentPC $ = WRITELINE(5,"$CurrentPC, ") $ping = Ping($CurrentPC) IF $ping $WMICheck = ConfirmWMI($CurrentPC) IF $WMICheck >= '1085.0005' $MyBIOSInfo = GetBIOSInfo("$CurrentPC") $ = WRITELINE(5, $MyBIOSInfo[3] + @CRLF) Else $ = WRITELINE(5, "WMI not responding." + @CRLF) Endif ELSE $ = WRITELINE(5, "Did not respond." + @CRLF) ENDIF
$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
Function Ping($PC) Shell'%comspec% /c ping -n 1 '+$PC+' >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
Sorry, didn't see post #155619. I tried that script and for some reason it started out with a different computer and worked, then went onot the first computer in the list, then error'd out like all of the others...
Ok... I won't run my script. Your script skips the first computer, pulls the 2nd and 3rd's information and then errors out on the 4th... The reason I know that is because it shows the information for the 2nd and 3rd and then immediately errors out with the same error as b4.
#155984 - 2006-01-2603:34 AMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Can you create a new TEXT file and only run a couple of the computers in it please. Let me make a few changes and then I'll post again and you can run it and test it.
I've run this on a couple so I know it works. Let me make a few changes though. Be back in a bit.
#155986 - 2006-01-2603:54 AMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Okay, I've now ran this on a dozen computers and they all responded except for 1 which I put in a bogus name on purpose in the middle.
Please run this and then post back on the board the output so I can see what's going on.
Remember, only run this script, nothing you've added/modified before. Also make sure the text file of the computer names is new and created with something like NOTEPAD or other normal ASCII Editor and not something like MS Word, Wordpad, or Wordperfect.
copied and pasted that exact code into Notepad. Cut and pasted 13 of the computer names from the original list into another Notepad file and saved it with computer_list.txt. I ran the script. I got the same results:
You need to be careful that there are no trailing spaces in the text file. That was why I asked you to sent the name to the screen with square brackets. The GET command was simply to pause the script between iterations.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
Ran perfectly, thanx so much for the help gentlemen! I'll work on it from here NTDOC to see if I can get it to write to a file. THANX SO MUCH AGAIN GUYS!!! I APPRECIATE YOU GUYS CHOKING THROUGH THAT WITH ME!!!
p.s. it's the end of my shift here in Iraq so I'll talk to you gents tomorrow!
#155992 - 2006-01-2605:42 AMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
Well I would never have thought of it, but Les was spot on with his diagnosis. It would appear that one or more of the computers in your list either had a leading space or a trailing space. I added some trailing spaces to my list of computers and got the same error you did. By adding the code below it then ran correctly again.
Thanks Les
By adding this, it removes any of those spaces in the file (though it's better if you didn't have spaces in the first place) $sComputer = Trim($sComputer)
Try this code out now and hopefully it should work correctly on your whole list. Then you can start working on logging it.
Hey Doc, I got some bad news; I just didn't let the script run long enough. I ran both the scripts in #155634 and #155631 and it still error'd out, just farther down the list. It just scrolled so much information last night when I saw it that I assumed it was working correctly. In troubleshooting, I had already opened my computer_list.txt file in both Notepad and Word and removed all single space characters so that should've stopped the problem if that WAS the problem.
To answer your questions, I'm in the military and I work on a medium size domain that is a tree in a much larger forest...
Something I just looked at too. I took a screen shot of the error before it closed and some of your error trapping may have caught the problem... Would an "Access is denied" error cause the problems I am seeing?
#155995 - 2006-01-2607:51 PMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
No an access denied should not stop the process as we did not set any code to quit on any error. The individual UDFS have exit codes but only to exit the UDF, not the main script.
Can you e-mail me the list so I can review it for potential issues? If not that's okay - things to look for are maybe special characters or names or spaces in the middle of names.
#155996 - 2006-01-2607:55 PMRe: Problems with calling array elements in strings...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: CA
ps Are you sure you're using the latest version of the script? You mentioned that in my error code outputs you see the error, but I don't have any in the last version.
Is if possible you've altered the script some how from what was posted last?
I emailed you the latest script, the computer list, a screen shot of the error, and a screen shot of my KiX version. serial5.kix has been the latest and all I did was cut and paste the code directly from KORG into the file and ran it. I tried both scripts from posts #155634 and #155631.