intMaxAge = 60
'Create Objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get special folder paths
strAllUserProfile = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
Set SkipProfilesArray = CreateObject("Scripting.Dictionary")
SkipProfilesArray.Add "Administrator", "Administrator"
SkipProfilesArray.Add "All Users","All Users"
SkipProfilesArray.Add "Default User","Default User"
SkipProfilesArray.Add "LocalService","LocalService"
SkipProfilesArray.Add "NetworkService","NetworkService"
strAllProfiles = objFSO.GetParentFolderName(strAllUserProfile)
Set objProfiles = objFSO.GetFolder(strAllProfiles)
For Each strUserProfile In objProfiles.SubFolders
If Not SkipProfilesArray.Exists(strUserProfile.Name) Then
Set objDAT = objFSO.GetFile(strUserProfile & "\NTUSER.DAT")
If DateDiff("D", objDAT.DateLastModified, Now()) > intMaxAge Then
objFSO.DeleteFolder strUserProfile
End If
End If
Next
|