For years I used a simple app named DeleteGU to delete TEMP files off a PCs hard drive from within PE. I used it before imaging, or just as a general cleanup utility. Alas, it is not compatible for Windows Vista / 7 / 8 and the author is no where to be found. So I wrote a simple batch file to do it with. It deletes USERS and SYSTEM temp files, Temporary Internet files and deletes the page file and hibernation file. I wanted something small and lean and without working through Runscanner.
Here are some issues:
- I can't suppress all error messages despite driving output into NUL
- I can't seem to actually DELETE the $RECYCLE.BIN, I can empty it but not deletes it, this causes a corruption error the first time Windows is started.
- 2 dependencies: ICACLS.EXE to enable deletion of the hiberfil.sys file, else access is denied, and ATTRIB.EXE, both must be in your build.
- I ran into some mysterious HIDDEN or READ ONLY files occasionally, this is why the extra step of using ATTRIB was added
- You must enter the REAL Windows OS drive a the prompt or command line, Wonko came up with a brilliant script to determine the REAL OS drive, but alas, I am too stupid to figure out how to combine it with this script. Check it out
So guys-n-gals, tear it apart, make it better or use it just the way it is. If we can get it looking better then I'll wrap it in a Winbuilder script to make it build ready.
@echo off :: DelTempFiles Script IF NOT "%1"=="" GOTO :SpecDrive echo. set /p DrvLet= Which drive holds the real Windows OS? e.g. C:, D: ^>^ set /A DrvLet-%DrvLet% :SpecDrive echo. if not exist %DrvLet%\Users Echo Not a valid Drive letter, try again! && echo. && pause && goto :EOF echo. echo Please wait, this may take some time echo. echo Please ignore any errors echo. %DrvLet% cd \Users dir echo. echo Do a CTRL-BREAK if the above does not show the Users folders echo. pause :: Crawl the USER directories entries and deleted all TEMP and TEMPORARY INTERNET files for /D %%a in (*.*) do ATTRIB -H -S -R /s /D "%%a\AppData\Local\Temp\*.*" >nul for /D %%a in (*.*) do DEL /F /S /Q "%%a\AppData\Local\Temp\*.*" >nul for /D %%a in (*.*) do FOR /D %%b IN ("%%a\AppData\Local\Temp\*.*") DO RD /S /Q "%%b" >nul REM Clean IE Cache for /D %%a in (*.*) do ATTRIB -H -S -R /s /D "%%a\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >nul for /D %%a in (*.*) do DEL /F /S /Q "%%a\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >nul for /D %%a in (*.*) do FOR /D %%b IN ("%%a\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*") DO RD /S /Q "%%b" >nul :: Clean ROOT Temp folder if there is one IF NOT EXIST \TEMP GOTO :SKIPROOTTEMP ATTRIB -H -S -R /S /D \temp\*.* >nul DEL /F /S /Q \temp\*.* >nul RD /S /Q \temp\*.* >nul :SKIPROOTTEMP IF NOT EXIST \Windows\TEMP GOTO :SKIPWINTEMP :: Clean Windows\Temp folder if there ATTRIB -H -S -R /S /D \Windows\temp\*.* >nul DEL /F /S /Q \Windows\temp\*.* >nul RD /S /Q \Windows\temp\*.* >nul :SKIPWINTEMP :: Clean the RECYCLE.BIN icacls \$Recycle.bin /t /grant everyone:F attrib -H -S -R /S /D \$Recycle.bin\*.* >nul attrib -H -S -R \$Recycle.bin >nul DEL /F /S /Q \$Recycle.Bin\*.* >nul RD /S /Q \$Recycle.Bin\*.* > nul RD /Q \$Recycle.Bin >nul IF NOT EXIST \pagefile.sys goto :SKIPPAGEFILE Echo Delete the pagefile.sys attrib -H -S \pagefile.sys >nul DEL /F /Q \pagefile.sys >nul :SKIPPAGEFILE Echo Delete the hiberfil.sys icacls \hiberfil.sys /grant everyone:F attrib -H -S \hiberfil.sys >nul DEL /F /Q \hiberfil.sys >nul echo. echo. echo. Echo All done . . . echo. pause