Submitted By: Seán Rooney

Checks the version of a particular .DLL or other file across a range of servers. In this case I'm searching for Ntfrs.exe, but you can change that as needed.

Visual Basic
Edit|Remove
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
'
' NAME: filever.vbs
'
' AUTHOR: Sean Rooney
' DATE  : 16/06/2005
'
' COMMENT: Check the file version for a particular file
'
'==========================================================================

arrayComputers = Array("server1","server2","server3")

For Each strServer in arrayComputers
    
    If Not Reachable(strserver) Then
        Wscript.Echo(strServer & ", Server Not Available")
    Else
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")

        Set colFiles = objWMIService.ExecQuery _
            ("Select * from CIM_Datafile Where name = 'c:\\winnt\\system32\\ntfrs.exe'")
    
        For Each objFile in colFiles
            Wscript.Echo strServer & ", Version: " & objFile.Version
            Next
    End If

Next

Function Reachable(HostName)
     Dim wshShell, fso, tfolder, tname, TempFile, results, retString, ts
     Const ForReading = 1, TemporaryFolder = 2
     Reachable = false

     Set wshShell = wscript.createobject("wscript.shell")
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
     tname = fso.GetTempName
     TempFile = tfolder & tname
     wshShell.run "cmd /c ping -n 3 -w 1000 " & HostName & ">" & TempFile,0,true
     Set results = fso.GetFile(TempFile)
     Set ts = results.OpenAsTextStream(ForReading)
     Do While ts.AtEndOfStream <> True
          retString = ts.ReadLine
          If instr(retString, "Reply") > 0 Then
               Reachable = true
               Exit Do
          End If
     Loop
     ts.Close
     results.delete

     Set ts = Nothing
     Set results = Nothing
     Set tfolder = Nothing
     Set fso = Nothing
     Set wshShell = Nothing
End Function