Skip to content

Instantly share code, notes, and snippets.

@zalmyr
Last active January 19, 2023 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zalmyr/137a36461cbe371e84a8 to your computer and use it in GitHub Desktop.
Save zalmyr/137a36461cbe371e84a8 to your computer and use it in GitHub Desktop.
BATCH: Clean Windows 7 Temp Files
REM Created by Zalmy Rosenberg © 2015
REM start /wait taskkill /im iexplore.exe /t /f
REM start /wait taskkill /im firefox.exe /t /f
REM start /wait taskkill /im chrome.exe /t /f
set user=C:\Users
set dest2=AppData\Local\Microsoft\Windows\Temporary Internet Files
set ffPath=AppData\Local\Mozilla\Firefox\Profiles
set chromePath=AppData\Local\Google\Chrome\User Data
set localTempPath=AppData\Local\Temp
set edgePath=AppData\Local\Microsoft\Edge\User Data
for /f "tokens=*" %%G in (
'dir /b /a:d "%user%"'
) do (
(REM Delete Temp Internet Files IE
if exist "%user%\%%G\%dest2%\" (del /s /q "%user%\%%G\%dest2%\*"
attrib /D /S -h -s "%user%\%%G\%dest2%\*"
for /f "tokens=*" %%5 in ('dir /A:D /b "%user%\%%G\%dest2%\"') do rd /S /Q "%user%\%%G\%dest2%\%%5"
)
)
(REM Firefox Temporary Files
if exist "%user%\%%G\%ffPath%" (
for /f %%H in ('dir /b /a:d %user%\%%G\%ffPath%') do (
del /s /q %user%\%%G\%ffPath%\%%H\cache2\*
del /s /q %user%\%%G\%ffPath%\%%H\OfflineCache\*
del /s /q %user%\%%G\%ffPath%\%%H\startupCache\*
del /s /q %user%\%%G\%ffPath%\%%H\safebrowsing\*
)
)
)
(REM Chrome Temp Files
if exist "%user%\%%G\%chromePath%" (
pushd "%user%\%%G\%chromePath%"
for /f "tokens=*" %%I in ('dir /b /s /a:d Cache') do (
del /s /q "%%I\*"
)
popd
)
)
(REM Edge Temp Files
echo "%user%\%%G\%edgePath%"
if exist "%user%\%%G\%edgePath%" (
pushd "%user%\%%G\%edgePath%"
for /f "tokens=*" %%I in ('dir /b /s /a:d Cache') do (
del /s /q "%%I\*"
)
popd
)
)
(REM Clean Windows Temp Files
echo "%user%\%%G\%localTempPath%\*"
if exist "%user%\%%G\%localTempPath%\" (
attrib /D /S -h -s "%user%\%%G\%localTempPath%\\*"
del /s /q "%user%\%%G\%localTempPath%\\*"
for /f "tokens=*" %%d in ('dir /b /a:d "%user%\%%G\%localTempPath%\"') do rd /S /Q "%user%\%%G\%localTempPath%\\%%d"
)
)
)
net stop wuauserv
net stop bits
rd /s /q %windir%\softwaredistribution
net start bits
net start wuauserv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment