@ECHO OFF :: First check for Windows version IF NOT "%OS%"=="Windows_NT" GOTO Syntax :: Enable delayed variable expansion SETLOCAL ENABLEDELAYEDEXPANSION :: Check for command line arguments -- none allowed IF NOT "%~1"=="" GOTO Syntax :: Second check for Windows version -- XP required VER | FIND.EXE "Windows XP" >NUL || GOTO Syntax :: Set temporary file name SET RegFile="%Temp%.\~FlushBin.tmp" :: Read the current settings for CleanMgr START /WAIT REGEDIT.EXE /E %RegFile% "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" :: Find an unused job number CALL :FindUnused :: Create a temporary file with the new job settings > %RegFile% ECHO REGEDIT4 >> %RegFile% ECHO. :: These WILL be cleaned FOR %%A IN ("Internet Cache Files" "Old ChkDsk Files" "Recycle Bin" "Temporary Files") DO ( >> %RegFile% ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%%~A] >> %RegFile% ECHO "StateFlags%Unused%"=dword:00000002 >> %RegFile% ECHO. ) :: These WON'T be cleaned FOR %%A IN ("Active Setup Temp Folders" "Compress old files" "Content Indexer Cleaner" "Downloaded Program Files" "Memory Dump Files" "Microsoft_Event_Reporting_2.0_Temp_Files" "Office Setup Files" "Offline Files" "Offline Pages Files" "Remote Desktop Cache Files" "Setup Log Files" "Temporary Offline Files" "WebClient and WebPublisher Cache") DO ( >> %RegFile% ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%%~A] >> %RegFile% ECHO "StateFlags%Unused%"=dword:00000000 >> %RegFile% ECHO. ) :: Import the job in the registry START /WAIT REGEDIT.EXE /S %RegFile% :: Run the cleanup job START /WAIT CLEANMGR.EXE /SageRun:%Unused% :: Create a temporary file to delete the new job > %RegFile% ECHO REGEDIT4 >> %RegFile% ECHO. FOR %%A IN ("Internet Cache Files" "Old ChkDsk Files" "Recycle Bin" "Temporary Files" "Active Setup Temp Folders" "Compress old files" "Content Indexer Cleaner" "Downloaded Program Files" "Memory Dump Files" "Microsoft_Event_Reporting_2.0_Temp_Files" "Office Setup Files" "Offline Files" "Offline Pages Files" "Remote Desktop Cache Files" "Setup Log Files" "Temporary Offline Files" "WebClient and WebPublisher Cache") DO ( >> %RegFile% ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%%~A] >> %RegFile% ECHO "StateFlags%Unused%"=- >> %RegFile% ECHO. ) :: Delete the new job from the registry START /WAIT REGEDIT.EXE /S %RegFile% :: Delete the temporary file DEL %RegFile% :: Done ENDLOCAL GOTO:EOF :FindUnused SET Unused=1000 FOR /L %%A IN (1001,1,1100) DO IF "!Unused!"=="1000" CALL :CheckIfUsed %%A IF %Unused% GTR 1000 GOTO:EOF FOR /L %%A IN (1101,1,2000) DO IF "!Unused!"=="1000" CALL :CheckIfUsed %%A IF %Unused% GTR 1000 GOTO:EOF FOR /L %%A IN (2001,1,9999) DO IF "!Unused!"=="1000" CALL :CheckIfUsed %%A GOTO:EOF :CheckIfUsed IF %Unused% GTR 1000 GOTO:EOF TYPE %RegFile% | FINDSTR.EXE /R /B /I /C:".StateFlags%1.=dword:" IF ERRORLEVEL 1 SET Unused=%1 GOTO:EOF :Syntax ECHO. ECHO FlushBin.bat, Version 1.00 for Windows XP ECHO Cleanup IE cache, ChkDsk files and temporary files, and empty the Recycle Bin ECHO. ECHO Usage: FLUSHBIN ECHO. ECHO Notes: This batch file uses CLEANMGR.EXE /SageRun:nnnn to run a cleanup job, ECHO but creates the cleanup job by writing it directly to the registry ECHO instead of using CLEANMGR.EXE /SageSet:nnnn ECHO CLEANMGR.EXE will perform a slow, unattended (not silent) cleanup. ECHO The cleanup job will be removed from the registry when finished. ECHO More info can be found at http://support.microsoft.com/kb/253597 ECHO and http://forums.scotsnewsletter.com/index.php?showtopic=10239 ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com IF "%OS%"=="Windows_NT" ENDLOCAL