I've used this to some success. You may need to edit it for your environment, but for me it works for XP Vista and 7. Couple of things, make sure it runs at a time with the least impact, and understand that it is as intrusive as you can really get, since it removes the folders and re creates them. You could change the rmdir
to del /f
and add a \
to the end of the file paths and then remove the mkdir
line if you would prefer to not remove the folders and just delete the contents.
This DELETES a ton of stuff, use at your own risk.
@echo off
IF EXIST c:\windows\temp\ del /f /s /q c:\windows\temp\
DEL /f /s /q %temp%\
IF EXIST "C:\Documents and Settings\" (
for /D %%x in ("C:\Documents and Settings\*") do (
rmdir /s /q "%%x\Local Settings\Temporary Internet Files"
mkdir "%%x\Local Settings\Temporary Internet Files"
)
)
IF EXIST "C:\Documents and Settings\" (
for /D %%x in ("C:\Documents and Settings\*") do (
rmdir /s /q "%%x\Local Settings\Temp"
mkdir "%%x\Local Settings\Temp"
)
)
IF EXIST "C:\Users\" (
for /D %%x in ("C:\Users\*") do (
rmdir /s /q "%%x\AppData\Local\Temp"
mkdir "%%x\AppData\Local\Temp"
)
)
IF EXIST "C:\Users\" (
for /D %%x in ("C:\Users\*") do (
rmdir /s /q "%%x\AppData\Local\Microsoft\Windows\Temporary Internet Files"
mkdir "%%x\AppData\Local\Microsoft\Windows\Temporary Internet Files"
)
)
Note this separates out the different folders, mostly for clarity but if you wanted to condense it you could compress it to only 2 loops. An example would be:
IF EXIST "C:\Users\" (
for /D %%x in ("C:\Users\*") do (
rmdir /s /q "%%x\AppData\Local\Temp"
mkdir "%%x\AppData\Local\Temp"
rmdir /s /q "%%x\AppData\Local\Microsoft\Windows\Temporary Internet Files"
mkdir "%%x\AppData\Local\Microsoft\Windows\Temporary Internet Files"
)
)
Per request, compressed and using delete command.
@echo off
IF EXIST c:\windows\temp\ del /f /s /q c:\windows\temp\
DEL /f /s /q %temp%\
IF EXIST "C:\Users\" (
for /D %%x in ("C:\Users\*") do (
del /f /s /q "%%x\AppData\Local\Temp\"
del /f /s /q "%%x\AppData\Local\Microsoft\Windows\Temporary Internet Files\"
)
)
IF EXIST "C:\Documents and Settings\" (
for /D %%x in ("C:\Documents and Settings\*") do (
del /f /s /q "%%x\Local Settings\Temp\"
del /f /s /q "%%x\Local Settings\Temporary Internet Files\"
)
)