Friday, April 10, 2009

A Little More Glue and Tape

Here’s another, rather simple script I wrote. This one simply scours a list of computers (text file, one computer name per line) and uses the FileSystemObject to query for a specific file on each computer. Of course, you need to ensure you run this with sufficient permissions to poke at all the remote computers C$ share (administrator rights), and that you don’t overlook client firewall settings or other such roadblocks to network communications.

Option Explicit

Const rmtPath = “\\COMPUTER\c$\Windows\System32\filename.exe”
Const inputFile = "computerlist.txt"
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim linecount, objFSO, objFile, ln, objTextFile, strLine, strPath

linecount = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objTextFile = objFSO.OpenTextFile(inputFile, ForReading)
If Err.Number <> 0 Then
Wscript.Echo "error: " & Err.Number & " / " & Err.Description
Set objFSO = Nothing
Wscript.Quit
End If

Do Until objTextFile.AtEndOfStream
strLine = Trim(objTextFile.Readline)
If Left(strLine,1) <> ";" And strLine <> "" Then
Wscript.Echo "querying " & strLine
strPath = Replace(rmtPath, "COMPUTER", strLine)
Wscript.Echo vbTab & "searching for file: " & strPath
If objFSO.FileExists(strPath) = True Then
Wscript.Echo vbTab & "file was found!"
Else
Wscript.Echo vbTab & "file was not found"
End If
End If
Loop

objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing

No comments: