WMI script to find files last accessed on a certain date

dtDate = "5/2/2005"

strSearchFolder = "C:Windows"

Set objFSO = CreateObject("Scripting.FileSystemObject")

WScript.Echo "File(s) last accessed on: " & dtDate & " in: " & strSearchFolder

EnumAndCheckFiles objFSO.GetFolder(strSearchFolder), dtDate

Sub EnumAndCheckFiles(objFolder, dtDate)

    Set objFiles = objFolder.Files

    For Each objFile in objFiles

    CheckFile objFile, dtDate


    For Each objSubfolder in objFolder.SubFolders

        EnumAndCheckFiles objSubfolder, dtDate


End Sub

Sub CheckFile(objFile, dtDate)

    If DateDiff("d", objFile.DateLastAccessed, dtDate) = 0 Then

        WScript.Echo objFile.Path

    End if

End Sub

3 Comments on WMI script to find files last accessed on a certain date

    • I have been working in IT for quite some time but have almost solely used bat/cmd files for scripting. Is there something special to getting a VB script to work? Thanks. Sorry for seeming stupid?

      • You need to use an admin account to run the script. You can run the vbscript in a command prompt window by typing:

        cscript script-name.vbs

Leave a Reply

Social Widgets powered by AB-WebLog.com.

Advertisment ad adsense adlogger