Is anyone in this community using a particular technique to achieve batch deletion of temporary data (such as Windows temp folders, browsers cache, etc) for all users?
The tricky part seems to be:
- Use a technique/tool that will be updated over time to meet changes in each product folder structure
- Allow access to other users folders (run as administrator/maximum privileges)
Scripts/batch files could be a solution, but it would require constant monitoring for each product update, to avoid deletion of older files/folder structures…
Your thoughts?
Best Answer
I had the same question, but motivated by the desire to aid my efforts to finish off malware cleanup operations. Here's the command script I wrote with an eye toward modularization so it could be extended easily for future OSes and temp file locations (I wrote this before learning PowerShell and haven't bothered to update it). Because it accesses every users profile folder on the machine as well as Windows system folders, the script must be run with elevated privileges.
Extending the Script's Functionality
Part of the script's extensibility is found in its use of the
:RemoveSubfoldersAndFiles
procedure. To delete the contents of a folder, simply call this procedure and pass a folder path as the only parameter (without double-quotes). The routine will gracefully handle paths that don't exist, folders that cannot be accessed for any reason, or the case where some files or folders below the path are in use or otherwise refuse to be deleted.To clean up additional folders found in each user's profile
In the section
Rem Clean up these folders
add additional calls to the :RemoveSubfoldersAndFiles subroutine. For example, to delete everything in each user's\AppData\Local\Microsoft\Windows\Temporary Internet Files
folder add the line:Note the use of the script-defined
%UserProfilePath%
variable instead of the typical%USERPROFILE%
variable. The script's version is dynamically updated as the script iterates through each user profile on the machine.To clean up folders found outside user profiles
In the
:SetUserProfPath
subroutine, again add calls to the :RemoveSubfoldersAndFiles procedure. For example: