Verify that a File Exists

This is a simple script that will check if a file exists, if not it will generate a warning event in the local event viewer. You can pick up that event with a rule from MOM. In this example, the script verify if C:\pagefile.sys exists.

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

strFile = “C:\pagefile.sys”

If objFSO.FileExists(strFile) Then
    Set objFolder = objFSO.GetFile(strFile)
Else
    Const EVENT_WARNING = 2
    Set objShell = CreateObject(“Wscript.Shell”)
    objShell.LogEvent 2, strFile & ” is not accessible.”
End If

One thought on “Verify that a File Exists

Comments are closed.