×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

vbfind

vbfind

(OP)
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!!

RE: vbfind

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.

Set colFiles = objWMIService.ExecQuery("Select Name, FileSize from CIM_DataFile" _
        & " where Name='" & replace(FILE,"\","\\") & "'")

Then the for-next part...

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

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

RE: vbfind

(OP)
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!!

RE: vbfind

(OP)
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!!

RE: vbfind

Xavier2,

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

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

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

- tsuji

RE: vbfind

Correction (typos):

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

- tsuji

RE: vbfind

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close