Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbfind 1

Status
Not open for further replies.

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 = fso_OpenTextFile(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!!
 
Hello Xavier2,

The problem with your go sub is that the properties are misunderstood in their syntax and contents.

A shortcut to change it is to retrieve the file directly.
[tt]
Set colFiles = objWMIService.ExecQuery("Select Name, FileSize from CIM_DataFile" _
& " where Name='" & replace(FILE,"\","\\") & "'")
[/tt]
Then the for-next part...
[tt]
if colFiles.count=0 then
wscript.echo "INFO: " & strComputer & " does not have " & FILE & " at the location."
else
For Each objFile in colFiles
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
Next
end if
[/tt]
Messages etc are not perfect but you get the idea.

Main thing is path in the wql statement does not include drive name and the "filename" and backslash is escaped. Name is the full name with full path included. Filename is the bare name without info on the path leading to it. So your colFiles is empty, hence, no message at all.

regards - tsuji
 
you rock, thanks for the info, i'm pretty much a novice at this so I'll give it a try and right before I jump out the window I'll ask for some more help...

thanks again...

Doh!!
 
Something is still wrong, I can get the errored out PC's but the good data is just lost, I'm lost


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 = "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 & "")
Set colFiles = objWMIService.ExecQuery("Select Name, FileSize from CIM_DataFile" _
& " where Name='" & replace(FILE,"\","\\") & "'")

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

Doh!!
 
Xavier2,

I just have a quick look. (I can think about it during weekend.)

I think when you compare file name like
[tt] if objFile.name=FILE then[/tt]
you should do it by first uniformizing the case, like this:
[tt] if lcase(objFile.name)=lcase(file)[/tt]

Whereas, in the wql the compare is not internally with case-insensitive built-in.

- tsuji
 
Correction (typos):

I meant [1]:
[tt] if lcase(objFile.name)=lcase(file) then[/tt]
and that [2]:
Whereas, in the wql the compare is [blue]done[/blue] internally with case-insensitive built-in.

- tsuji
 
Further note:

In the revised query string, it is understood if ever anything retrieved, objFile.name=FILE is guaranteed by design. So the testing is just a left-over from the previous query string. (But, if done properly, it would do any harm.)

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top