Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Batch delete temporary Windows files (system, browsers, cache, etc) for all users

General Tech Learning Aids/Tools

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months 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:

  • 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?

usr_profile.png

User

( 4 months ago )

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

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif