Submitted By: Gunter Danzeisen

Verifies the existence of a file on a remote computer.

Visual Basic
Edit|Remove
strComputer = "."
' Replace the dot with the remote computer name

strFile="C:\\windows\\test.txt"
' The file name needs to be in this format

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _

    & strComputer & "\root\cimv2")

 
Set colFiles = objWMIService.ExecQuery("SELECT * FROM CIM_Datafile WHERE Name = '" & strFile & "'")

 
For Each objFile in colFiles

    Wscript.Echo "File: " & objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension & " exists."
    

Next