5/10/2005

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
Next
For Each objSubfolder in objFolder.SubFolders
EnumAndCheckFiles objSubfolder, dtDate
Next
End Sub

Sub CheckFile(objFile, dtDate)
If DateDiff("d", objFile.DateLastAccessed, dtDate) = 0 Then
WScript.Echo objFile.Path
End if
End Sub



1 Comments:

Blogger Yimin said...

You can use a script like this to find exe files.

'--begin
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile" & _
" WHERE Drive = 'c:' AND Extension = 'exe'")
for each colFile in colFiles
WScript.Echo colFile.Name
next
'--end


You might want to review the files first before you delete them. I don't know about jump drives.

2:07 PM  

Post a Comment

<< Home