Cleaning batch (.bat) All Windows versions

greg1107 Posted messages 71 Status Membre -  
SALSABYL2018 Posted messages 1 Registration date   Status Membre Last intervention   -
Hello,

I'm looking for batch cleanup scripts (.bat) for the Windows versions of XP, Vista, Seven, Windows Server 2003, as well as for Windows Server 2008.
If possible, I would like these scripts to be independent and as comprehensive as possible.
I have already found some for XP on different forums (are they really complete?), but are there differences in certain files to target for cleanup with the other versions of Windows?
Thank you for your response; all suggestions are welcome as this is to carry out part of my final study project.
I'm counting on you since this is my first post :)

Greg1107

2 réponses

BeFaX Posted messages 16334 Status Contributeur 3 864
 
I created one for Windows Seven, I’ll hand you my source:

 :: Program created by BeFa :: Member of batch.xoo.it title BFSCleaner by BeFa Rem ---------------------- Copyright ---------------------------------- :: Code by BeFa, do not copy, modify, distribute this code without my permission :: Do not remove this Copyright, thank you. Rem ---------------------- Copyright ---------------------------------- (echo. echo ^|==================================================================^| echo ^| Recent Files ^| echo ^|==================================================================^|)>log.txt dir /B "%appdata%\Microsoft\Windows\Recent\*.lnk" 2>nul if "%errorlevel%"=="1" echo ^|>>log.txt for /f "delims=" %%a in ('dir /B "%appdata%\Microsoft\Windows\Recent\*.lnk"') do ( del /F /S /Q "%appdata%\Microsoft\Windows\Recent\%%a" if exist "%appdata%\Microsoft\Windows\Recent\%%a" (echo ^|%appdata%\Microsoft\Windows\Recent\%%a - [Locked]>>log.txt) else (echo ^|%appdata%\Microsoft\Windows\Recent\%%a - Deleted>>log.txt)) (echo ^|==================================================================^| echo ^| Temporary Windows Files ^| echo ^|==================================================================^|)>>log.txt for /f "delims=" %%a in ('dir /A:D /B %tmp%') do ( rmdir /S /Q "%tmp%\%%a" if exist "%temp%\%%a" (echo ^|%tmp%\%%a\ - [Locked]>>log.txt) else (echo ^|%tmp%\%%a\ - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /B %tmp%') do ( del /F /S /Q "%tmp%\%%a" if exist "%temp%\%%a" (echo ^|%tmp%\%%a - [Locked]>>log.txt) else (echo ^|%tmp%\%%a - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /A:D /B %windir%\TEMP') do ( rmdir /S /Q "%windir%\TEMP\%%a" if exist "%windir%\Temp\%%a" (echo ^|%windir%\Temp\%%a\ - [Locked]>>log.txt) else (echo ^|%windir%\Temp\%%a\ - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /B %windir%\TEMP') do ( del /F /S /Q "%windir%\TEMP\%%a" if exist "%windir%\TEMP\%%a" (echo ^|%windir%\Temp\%%a - [Locked]>>log.txt) else (echo ^|%windir%\TEMP\%%a - Deleted>>log.txt)) (echo ^|==================================================================^| echo ^| Temporary Internet Files ^| echo ^|==================================================================^|)>>log.txt set FIT=0 for /f "delims=" %%a in ('dir /B "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\*.dat"') do ( DEL /Q /F "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a" set FIT=1 if exist "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a" (echo ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - [Locked]>>log.txt) else (echo ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - Deleted>>log.txt)) if exist "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" ( attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" if exist "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\desktop.ini - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\desktop.ini - Deleted>>log.txt)) if exist "%tmp%\Temporary Internet Files\Content.IE5\index.dat" ( attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\index.dat" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\index.dat" if exist "%tmp%\Temporary Internet Files\Content.IE5\dindex.dat" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\index.dat - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\index.dat - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Temporary Internet Files\Content.IE5\"') do ( attrib -H -S -D -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\" attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini - Deleted>>log.txt) for /f "delims=" %%b in ('dir /B "%tmp%\Temporary Internet Files\Content.IE5\%%a\"') do ( attrib -A -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" set FIT=1 if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b - Deleted>>log.txt))) for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Temporary Internet Files\Content.IE5\"') do ( RMDIR /Q /S "%tmp%\Temporary Internet Files\Content.IE5\%%a\" set FIT=1 if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\ - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\ - Deleted>>log.txt)) if "%FIT%"=="0" echo ^|>>log.txt (echo ^|==================================================================^| echo ^| Windows Cookies ^| echo ^|==================================================================^|)>>log.txt set cook=0 for /f "delims=" %%a in ('dir /B %appdata%\Microsoft\Windows\Cookies') do ( del /F /S /Q "%appdata%\Microsoft\Windows\Cookies\%%a" set cook=1 if exist "%windir%\TEMP\%%a" (echo ^|%appdata%\Microsoft\Windows\Cookies\%%a - [Locked]>>log.txt) else (echo ^|%appdata%\Microsoft\Windows\Cookies\%%a - Deleted>>log.txt)) if exist "%appdata%\Microsoft\Windows\Cookies\" ( rmdir /S /Q "%appdata%\Microsoft\Windows\Cookies\" set cook=1 if exist "%appdata%\Microsoft\Windows\Cookies\" (echo ^|%appdata%\Microsoft\Windows\Cookies\ - [Locked]>>log.txt) else (echo ^|%appdata%\Microsoft\Windows\Cookies\ - Deleted>>log.txt)) if "%cook%"=="0" echo ^|>>log.txt (echo ^|==================================================================^| echo ^| Prefetch Files ^| echo ^|==================================================================^|)>>log.txt dir /B "%windir%\Prefetch\*.pf" if "%errorlevel%"=="1" echo ^|>>log.txt for /f "tokens=*" %%a in ('dir /B "%windir%\Prefetch\*.pf"') do ( DEL /F /S /Q "%windir%\Prefetch\%%a" if exist "%WINDIR%\Prefetch\%%a" (echo ^|%WINDIR%\Prefetch\%%a - [Locked]>>log.txt) else (echo ^|%WINDIR%\Prefetch\%%a - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /B /A:D "%localappdata%\Mozilla\Firefox\Profiles"') do ( set profile=%localappdata%\Mozilla\Firefox\Profiles\%%a set ff=%localappdata%\Mozilla\Firefox\Profiles\%%a) (echo ^|==================================================================^| echo ^| Mozilla Firefox Cache ^| echo ^|==================================================================^|)>>log.txt set cacheff=0 for /f "delims=" %%a in ('dir /B /A:D "%localappdata%\Mozilla\Firefox\Profiles"') do ( set profile=%localappdata%\Mozilla\Firefox\Profiles\%%a set prof=%%a) if exist "%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite" ( set cacheff=1 DEL /Q /F "%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite" if exist "%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite" (echo ^|%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite - [Locked]>>log.txt) else (echo ^|%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /B /A:D "%profile%"') do call :ff %%a for /f "delims=" %%a in ('dir /B /A:D "%profile%"') do ( rmdir /S /Q "%profile%\%%a" if exist "%profile%\%%a" (echo ^|%profile%\%%a\ - [Locked]>>log.txt) else (echo ^|%profile%\%%a\ - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /B /A:D "%profile%"') do set cacheff=1 if "%cacheff%"=="0" echo ^|>>log.txt goto next1 :ff set cacheff=1 set var=%* for /f "delims=" %%a in ('dir /B "%profile%\%var%\"') do ( del /F /S /Q "%profile%\%var%\%%a" if exist "%profile%\%var%\%%a" (echo ^|%profile%\%var%\%%a - [Locked]>>log.txt) else (echo ^|%profile%\%var%\%%a - Deleted>>log.txt)) goto :eof :next1 (echo ^|==================================================================^| echo ^| Macromedia Flash Player ^| echo ^|==================================================================^|)>>log.txt set flash=0 for /f "delims=" %%a in ('dir /A:D /B "%appdata%\Macromedia\Flash Player\#SharedObjects\"') do ( for /f "delims=" %%b in ('dir /A:D /B "%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\"') do ( RMDIR /Q /S "%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\%%b\" set flash=1 if exist "%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\%%b\" (echo ^|%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\%%b\ - [Locked]>>log.txt) else (echo ^|%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\%%b\ - Deleted>>log.txt))) for /f "delims=" %%a in ('dir /A:D /B "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\"') do ( rmdir /Q /S "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\%%a\" if exist "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\%%a\" (echo ^|%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\%%a\ - [Locked]>>log.txt) else (echo ^|%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\%%a\ - Deleted>>log.txt)) if "%flash%"=="0" echo ^|>>log.txt (echo ^|==================================================================^| echo ^| Windows Defender ^| echo ^|==================================================================^|)>>log.txt set wdef=0 for /f "delims=" %%a in ('dir /B "%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\"') do ( DEL /Q /F "%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\%%a" set wdef=1 if exist "%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\%%a" (echo ^|%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\%%a - [Locked]>>log.txt) else (echo ^|%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\%%a - Deleted>>log.txt)) if "%wdef%"=="0" echo ^|>>log.txt start log.txt


So, it deletes:
Recent Files
Temporary Windows Files
Windows Cookies
Prefetch Files
Mozilla Firefox Cache
Macromedia Flash Player
Windows Defender


And for Temporary Internet Files, actually, I can't really delete them, it's just a list.
They get deleted from Windows Explorer, but just run a CCleaner to see that these temporary files are still there.

So, I'm still working on a program to completely delete them from the disk without using a third-party program.
Here’s where I am for temporary files, maybe it can help you, but as I told you, it doesn't delete them from the disk:

@echo off (echo ^|==================================================================^| echo ^| Temporary Internet Files ^| echo ^|==================================================================^|)>log.txt set FIT=0 for /f "delims=" %%a in ('dir /B "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\*.dat"') do ( DEL /Q /F "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a" set FIT=1 if exist "%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a" (echo ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - [Locked]>>log.txt) else (echo ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - Deleted>>log.txt)) if exist "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" ( attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" if exist "%tmp%\Temporary Internet Files\Content.IE5\desktop.ini" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\desktop.ini - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\desktop.ini - Deleted>>log.txt)) if exist "%tmp%\Temporary Internet Files\Content.IE5\index.dat" ( attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\index.dat" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\index.dat" if exist "%tmp%\Temporary Internet Files\Content.IE5\dindex.dat" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\index.dat - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\index.dat - Deleted>>log.txt)) for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Temporary Internet Files\Content.IE5\"') do ( attrib -H -S -D -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\" attrib -H -S -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\desktop.ini - Deleted>>log.txt) for /f "delims=" %%b in ('dir /B "%tmp%\Temporary Internet Files\Content.IE5\%%a\"') do ( attrib -A -I "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" DEL /F /Q "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" set FIT=1 if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\%%b - Deleted>>log.txt))) for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Temporary Internet Files\Content.IE5\"') do ( RMDIR /Q /S "%tmp%\Temporary Internet Files\Content.IE5\%%a\" set FIT=1 if exist "%tmp%\Temporary Internet Files\Content.IE5\%%a\" (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\ - [Locked]>>log.txt) else (echo ^|%tmp%\Temporary Internet Files\Content.IE5\%%a\ - Deleted>>log.txt)) if "%FIT%"=="0" echo ^|>>log.txt start log.txt
1
alias
 
topppppppppppp
0
SALSABYL2018 Posted messages 1 Registration date   Status Membre Last intervention  
 
TOPPPP !!! Great job, computer scientist! Hats off!
0
greg1107 Posted messages 71 Status Membre 2
 
Honestly, a big thank you, it feels really great!
That's some nice work!
:) yeah Rock'n'roll and sunshine to you! ;)

So I'm still looking for Vista, server 2003, and server 2008!

So batch cleaning and more comprehensive please. :)

BeFaX you are the best! ;)

to code or not to code that is the question!

greg1107
0