J
Jason Benway
This seems to fail when the machine is not online. I have a function to ping
the machine and return true or false. But it doesn't seem to be working.
Will someone please take a look:
thank you
'
============================================================================
===============
'
' Script Information
'
' Title: Bios Information
' Author: Jason Benway
' Description: list computer name,model,and bios version. Must pass txt file
containing list
' computer names. Output is written to c:\biosversions.txt
'
'
'
============================================================================
===============
Set objargs = WScript.Arguments
Const forreading = 1
Set acomputers = CreateObject("Scripting.Dictionary")
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objtextfile = objfso.OpenTextFile(objargs(0), forreading)
Set outfso = CreateObject("Scripting.FileSystemObject")
Set outtextfile = outfso.CreateTextFile("c:\biosversions.txt", True)
' Read the file which contains a list of machines, on per line
i = 0
Do While objtextfile.AtEndOfStream <> True
strnextline = objtextfile.ReadLine
acomputers.add i, strnextline
i = i + 1
Loop
For Each sComputer In aComputers
dcomputer = acomputers.Item(scomputer)
' check if computer is online
w = 0
' suppress errors
'On Error Resume Next
dcomputer = Replace(dcomputer, vbtab, "")
If IsConnectible(dcomputer,2,300) = True Then
Set oWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each wmiobj In oWMI.InstancesOf("Win32_ComputerSystem")
soutput = wmiObj.Caption & vbtab & wmiobj.model
Next
End If
Set aoWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each awmiobj In aoWMI.InstancesOf("Win32_BIOS")
soutput = soutput & vbtab & awmiObj.SMBIOSBIOSVersion
Next
End If
If err = 0 Then
WScript.Echo soutput
outtextfile.WriteLine soutput
End If
End If
Next
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"
oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function
the machine and return true or false. But it doesn't seem to be working.
Will someone please take a look:
thank you
'
============================================================================
===============
'
' Script Information
'
' Title: Bios Information
' Author: Jason Benway
' Description: list computer name,model,and bios version. Must pass txt file
containing list
' computer names. Output is written to c:\biosversions.txt
'
'
'
============================================================================
===============
Set objargs = WScript.Arguments
Const forreading = 1
Set acomputers = CreateObject("Scripting.Dictionary")
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objtextfile = objfso.OpenTextFile(objargs(0), forreading)
Set outfso = CreateObject("Scripting.FileSystemObject")
Set outtextfile = outfso.CreateTextFile("c:\biosversions.txt", True)
' Read the file which contains a list of machines, on per line
i = 0
Do While objtextfile.AtEndOfStream <> True
strnextline = objtextfile.ReadLine
acomputers.add i, strnextline
i = i + 1
Loop
For Each sComputer In aComputers
dcomputer = acomputers.Item(scomputer)
' check if computer is online
w = 0
' suppress errors
'On Error Resume Next
dcomputer = Replace(dcomputer, vbtab, "")
If IsConnectible(dcomputer,2,300) = True Then
Set oWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each wmiobj In oWMI.InstancesOf("Win32_ComputerSystem")
soutput = wmiObj.Caption & vbtab & wmiobj.model
Next
End If
Set aoWMI = GetObject("winmgmts:\\" & dComputer & "\root\cimv2")
If err = 0 Then
For Each awmiobj In aoWMI.InstancesOf("Win32_BIOS")
soutput = soutput & vbtab & awmiObj.SMBIOSBIOSVersion
Next
End If
If err = 0 Then
WScript.Echo soutput
outtextfile.WriteLine soutput
End If
End If
Next
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"
oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function