JimmyZ1
Technical User
- Mar 31, 2004
- 397
can someone tell me why this is just showing me the machines that error out, and not the machines that actually have adobe on them.... I'm losing my mind.
Option Explicit
On Error Resume Next
Const F_RDON = 1 ' Read-only
Const NPINGS = 2 ' # of ping attempts
Const TIMEOUT = 750 ' Time out in milliseconds
Dim fso, fd, file ' file references
Dim strComputer ' computer name read from file
Dim isAlive ' does machine respond to ping?
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'Check for correct number of command-line args
If Wscript.Arguments.Count <> 1 Then
wscript.echo "Usage: cbstart <file>, where <file> is a text file " & _
"with one computer name per line" & vbCRLF
wscript.quit
End If
file = ".\" & Wscript.Arguments.Item(0)
set fso = CreateObject("Scripting.FileSystemObject")
Set fd = fs
penTextFile(file, F_RDON)
If Err.Number <> 0 Then
wscript.echo "FATAL: Could not open " & file
wscript.quit
End If
'Extract filename and open the corresponding file. While machine names remain
'in the file, ping the next name and then process if it responds.
Do while Not fd.AtEndOfStream
strComputer = fd.ReadLine
isAlive = canConnect(strComputer,NPINGS,TIMEOUT)
If isAlive = 1 Then
Go strComputer
Else
wscript.echo "WARNING: Could not ping " & strComputer
End If
Loop
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' Change start mode to automatic and start service
Sub Go(strComputer)
On Error Resume Next
Dim objWMIService, colFiles, objFile ' WMI references
Const PATH = "D:\Program Files\Adobe\Acrobat 6.0\Reader\"
Const FILE = "D:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if err.Number <> 0 Then
wscript.echo "WARNING: Could not connect to WMI service on " & strComputer
err.clear
Else
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile" _
& " where Drive='d:' and Path=" & PATH & "")
if err.number <> 0 then
wscript.echo "WARNING:" & err.description & " on " & strComputer
err.clear
else
For Each objFile in colFiles
if objFile.Name = FILE then
if objFile.FileSize = 7671876 then
wscript.echo "INFO: " & strComputer & " has Version 6.0 " & objFile.FileSize
else
wscript.echo "CRITICAL: " & strComputer & " is out of date " & objFile.FileSize
end if
end if
Next
end if
End If
End Sub
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' Ping workstation name and return false if it doesn't respond, true if it does
Function canConnect(strComputer, NPINGS, TIMEOUT)
Dim oShell, oExCmd, pingResult
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & NPINGS & " -w " & TIMEOUT & _
" " & strComputer)
pingResult = oExCmd.StdOut.Readall
Select Case InStr(pingResult,"TTL=")
Case 0
canConnect = 0
Case Else
canConnect = 1
End Select
End Function
'------------------------------------------------------------------------------
Doh!!
Option Explicit
On Error Resume Next
Const F_RDON = 1 ' Read-only
Const NPINGS = 2 ' # of ping attempts
Const TIMEOUT = 750 ' Time out in milliseconds
Dim fso, fd, file ' file references
Dim strComputer ' computer name read from file
Dim isAlive ' does machine respond to ping?
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'Check for correct number of command-line args
If Wscript.Arguments.Count <> 1 Then
wscript.echo "Usage: cbstart <file>, where <file> is a text file " & _
"with one computer name per line" & vbCRLF
wscript.quit
End If
file = ".\" & Wscript.Arguments.Item(0)
set fso = CreateObject("Scripting.FileSystemObject")
Set fd = fs
If Err.Number <> 0 Then
wscript.echo "FATAL: Could not open " & file
wscript.quit
End If
'Extract filename and open the corresponding file. While machine names remain
'in the file, ping the next name and then process if it responds.
Do while Not fd.AtEndOfStream
strComputer = fd.ReadLine
isAlive = canConnect(strComputer,NPINGS,TIMEOUT)
If isAlive = 1 Then
Go strComputer
Else
wscript.echo "WARNING: Could not ping " & strComputer
End If
Loop
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' Change start mode to automatic and start service
Sub Go(strComputer)
On Error Resume Next
Dim objWMIService, colFiles, objFile ' WMI references
Const PATH = "D:\Program Files\Adobe\Acrobat 6.0\Reader\"
Const FILE = "D:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if err.Number <> 0 Then
wscript.echo "WARNING: Could not connect to WMI service on " & strComputer
err.clear
Else
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile" _
& " where Drive='d:' and Path=" & PATH & "")
if err.number <> 0 then
wscript.echo "WARNING:" & err.description & " on " & strComputer
err.clear
else
For Each objFile in colFiles
if objFile.Name = FILE then
if objFile.FileSize = 7671876 then
wscript.echo "INFO: " & strComputer & " has Version 6.0 " & objFile.FileSize
else
wscript.echo "CRITICAL: " & strComputer & " is out of date " & objFile.FileSize
end if
end if
Next
end if
End If
End Sub
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' Ping workstation name and return false if it doesn't respond, true if it does
Function canConnect(strComputer, NPINGS, TIMEOUT)
Dim oShell, oExCmd, pingResult
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & NPINGS & " -w " & TIMEOUT & _
" " & strComputer)
pingResult = oExCmd.StdOut.Readall
Select Case InStr(pingResult,"TTL=")
Case 0
canConnect = 0
Case Else
canConnect = 1
End Select
End Function
'------------------------------------------------------------------------------
Doh!!