' NAME: WMIModelandBIOS.vbs ' ' Alan Kaplan, alan@akaplan.com 7/18/2002 ' ' COMMENT: Gets Model and Bios Info ' ver 1.1 3/23/2010 cleaned up code, added SMB info, moved logfile to desktop ' added message box when run on single PC ' you can run this against a list of computers with a FOR command ' EX: for /f %s in (computerlist.txt) do cscript //nologo WMIModelAndBIOS.vbs %s ' '========================================================================== Option Explicit dim objEnv, wshShell, objWMIService Dim oHW, item, bversion Dim strComputer,strManufacturer,strModel,strBios,strserial Dim strIP Set wshShell = WScript.CreateObject("WScript.Shell") set objEnv = WshShell.Environment("process") strComputer = objEnv("COMPUTERNAME") 'Get local computer name Dim fso,logfile, appendout Dim bBatch 'Name of log file. Can open in Excel. delimiter is "," logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\ModelandBIOS.csv" If WScript.Arguments.count = 0 Then strComputer=InputBox("Enter name of PC","Check Model and BIOS Information",strComputer) bBatch = false Else strComputer=WScript.Arguments(0) End If On Error Resume Next strComputer = UCase(strComputer) If bBatch Then 'setup log Const ForAppend = 8 set fso = CreateObject("Scripting.FileSystemObject") Set AppendOut = fso.OpenTextFile(logfile, ForAppend, True) If Err <> 0 Then MsgBox "Close logfile " & logfile, vbcritical + vbokayonly WScript.Quit End If End If If PingReply = False Then EchoAndLog strComputer& ",,,,,Failed,No Reply" WScript.Quit End If Set objWMIService = GetObject("winmgmts://"& strComputer) If Err <> 0 Then EchoAndLog strComputer& ",,,,,Failed"& "," & err.description WScript.Quit End If 'HWInfo Set oHW = objWMIService.ExecQuery("select Manufacturer,Model from Win32_ComputerSystem") For Each item in oHW strManufacturer = trim(item.Manufacturer) strModel = trim(item.Model) Next 'not all manufacturers make this info available Set oHW = objWMIService.ExecQuery("select * from Win32_BIOS") For each item In oHW If item.SMBIOSpresent = True Then strBios = " (SMB BIOS: " & item.smbiosbiosversion & " ver. " & item.smbiosmajorversion & "." & item.smbiosminorversion & ")" End If if item.name = "Default System BIOS" then Bversion = trim(item.Version) Else bversion = item.name & " " & trim(item.Version) End If strBios = bversion & strBios strserial = trim(Item.SerialNumber) Next EchoandLog strComputer& "," & strManufacturer & "," & strModel& "," & strBios & "," &strserial & ",Success" Set objWMIService = Nothing Set fso = Nothing Sub EchoAndLog (message) If bBatch Then 'Echo output and write to log if IsCScript then Wscript.Echo message AppendOut.WriteLine message Else ' Break it up for a message box Dim aTemp aTemp = Split(message,",") message = "BIOS information for " & aTemp(0) & VbCrLf & VbCrLf if UBound(aTemp)= 5 Then message = message & aTemp(1) & " " & aTemp(2) & vbTab & _ "Serial Number: " & aTemp(4) & vbNewLine & _ "BIOS: " & aTemp(3) Else message = message & "Query Failed: " & aTemp(6) End If MsgBox message,vbOKOnly,aTemp(5) End If End Sub Function PingReply( ) Dim objScriptExec, strPingResults Dim objRE, match, matches 'RegEx pattern from Bill Stewart Set objRE = New RegExp objRE.Pattern = " [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}: " 'Three lines from Steve Cathersalc Set objScriptExec=wshShell.Exec("ping -n 2 -w 1000 " & strComputer) Set Matches = objRE.Execute(objScriptExec.StdOut.Readall) ' Execute search. If Matches.count = 1 Then PingReply = True For Each Match in Matches ' Iterate Matches collection. strIP = trim(replace(Match.Value,":","")) 'Cleanup Next Else strIP = "" PingReply = False End If End Function Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function