Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizGeneral Tech Learning Aids/Tools 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
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.
@echo off
Rem Temp File Purging Tool v1.2.0
Rem Written by Twisty. Created 1/19/2011. Modified 6/28/2011.
Rem
Rem This script deletes temp files in locations where malware likes to write its initial
Rem files for infection and also where standard users have write permissions.
Rem
Rem This tool isn't likely to be as helpful to clean systems on which users run with
Rem Admin permissions. If you let your users run with Admin permissions you by extension
Rem give much of the malware on the Internet permission to do as it pleases on your workstations.
Rem Identify version of Windows
SET WinVer=Unknown
VER | FINDSTR /IL "5.1." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVer=XP
rem 5.2 is actually Server 2003, but for our purposes it's the same as XP
VER | FINDSTR /IL "5.2." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVer=XP
VER | FINDSTR /IL "6.0." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA
rem 6.1 is actually Windows 7, but for our purposes it's the same as Vista
VER | FINDSTR /IL "6.1." > NUL
IF %ERRORLEVEL% EQU 0 SET WinVer=VISTA
rem Ask user the version if we cannot automatically determine
If Not "%WinVer%" EQU "Unknown" Goto :SetUserProfPath
Set /P Response="Select OS [X]P, [V]ista/7: "
If /i "%Response%" EQU "X" Set WinVer=XP
If /i "%Response%" EQU "V" Set WinVer=VISTA
If "%WinVer%" EQU "" Echo Invalid response. Exiting.&goto :eof
:SetUserProfPath
If %WinVer% EQU XP (
Set UserProfileRootPath=C:\Documents and Settings
) Else (
Set UserProfileRootPath=C:\Users
)
Call :RemoveSubfoldersAndFiles %SystemRoot%\Temp
Rem Walk through each user profile folder
Rem This convoluted command is necessary to ensure we process hidden and system folders too
for /f "delims=" %%D in ('dir /ad /b "%UserProfileRootPath%"') DO Call :ProcessProfileFolder %UserProfileRootPath%\%%D
Echo.
Echo Finished! Press a key to exit...
Pause>Nul
goto :EOF
:ProcessProfileFolder
Set FolderName=%*
Rem Leave if it's not a user profile folder
If Not Exist "%FolderName%\ntuser.dat" goto :EOF
Rem Leave it's a profile folder on the exclude list
If /I "%FolderName%" EQU "%UserProfileRootPath%\Default" goto :EOF
If /I "%FolderName%" EQU "%UserProfileRootPath%\Default User" goto :EOF
If /I "%FolderName%" EQU "%UserProfileRootPath%\NetworkService" goto :EOF
If /I "%FolderName%" EQU "%UserProfileRootPath%\LocalService" goto :EOF
Set UserProfilePath=%FolderName%
Rem Clean up these folders
If %WinVer% EQU XP (
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Temp
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Local Settings\Temporary Internet Files
Call :RemoveSubfoldersAndFiles %UserProfilePath%\Application Data\Sun\Java\Deployment\cache
) Else (
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Temp
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\LocalLow\Temp
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\LocalLow\Sun\Java\Deployment\cache
Call :RemoveSubfoldersAndFiles %UserProfilePath%\AppData\Local\Microsoft\Windows\Temporary Internet Files
)
goto :EOF
:RemoveSubfoldersAndFiles
Set FolderRootPath=%*
Rem Confirm target folder exists
If Not Exist "%FolderRootPath%" Goto :EOF
Rem Make the folder to clean current and confirm it exists...
CD /D %FolderRootPath%
Rem Confirm we switched directories
If /I "%CD%" NEQ "%FolderRootPath%" Goto :EOF
Rem ...so that this command cannot delete the folder, only everything in it
Echo Purging %CD%
RD /S /Q . >>nul 2>>&1
goto :EOF
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
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:
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?