It has comments, so there's no need to explain it, right? This is mainly for newbies learning FSO. Actually, when you have a shell, analyzing what programs the user has accessed recently and which programs they use most often is still quite helpful.
'Automatically call cscript to start the script
set oSh=CreateObject("WScript.Shell")
If lcase(right(WScript.FullName,11))="wscript.exe" Then
oSh.Run "cmd /ccscript //NoLogo //e:vbscript " & WScript.ScriptFullName
WScript.Quit
End If
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(Inputbox("Folder to analyze:",WScript.ScriptName,"D:\"))
Set oOutTxt=FSO.CreateTextFile("Recently accessed exe.txt",1)
EnumFolders(oFolder)
oOutTxt.Close
'Procedure for traversing folders, recursive
Sub EnumFolders(oTargetFolder)
For Each oSubFolder In oTargetFolder.SubFolders
'WScript.Echo oSubFolder
MostRecentExeFile(oSubFolder)
EnumFolders(oSubFolder)
Next
End Sub
'Procedure for getting the most recently accessed exe.
Sub MostRecentExeFile(oTargetFolder)
Dim a,i,MostRecent,MostRecentExe
For Each oFile In oTargetFolder.Files
If Right(oFile.Name,3)="exe" Then
i=i+1
CurrIndex=CurrIndex+1
If CCur(oFile.DateLastAccessed) > MostRecent Then
MostRecent=CCur(oFile.DateLastAccessed)
MostRecentExe=oFile
End If
End If
a=a+1
Next
If i> 0 Then p=i/a 'Prevent the case of folders that contain no exe
If (p<0.1 And MostRecentExe<>"") Then 'Conditions: 1. exe files account for less than 10% of all files. Some folders are just green portable tools, and getting only one result out of them is meaningless. It's more interesting to analyze folders like Office. 2. Prevent cases where some folders contain no exe
WScript.Echo MostRecentExe
oOutTxt.WriteLine MostRecentExe & Chr(9) & CDate(MostRecent)
End If
End Sub
