Cleaning batch (.bat) Toutes versions Windows

greg1107 Messages postés 71 Statut Membre -  
SALSABYL2018 Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour à vous,

Je recherche des scripts de nettoyage en batch (.bat) pour les versions Windows de XP, Vista, Seven, Windows Server 2003, de même que pour Windows Server 2008.
Si possible j'aimerais que ces scripts soient indépendants et les plus complets possible.
J'en ai déjà trouvé pour XP sur différents forums (sont-ils réellement complets?) : mais n'y a t'il pas des différences sur certains fichiers à pointer pour le nettoyage avec les autres versions de Windows?
Merci de me répondre, toutes les suggestions sont bonnes à prendre et ceci afin de réaliser une partie de mon travail de fin d'étude.
Je compte sur vous ces mon premier postes :)

Greg1107

2 réponses

  1. BeFaX Messages postés 16334 Statut Contributeur 3 863
     
    J'en ai créé un pour Windows Seven, je te file ma source :

    :: Programme crée par BeFa
    :: Membre de batch.xoo.it
    
    title BFSCleaner par BeFa
                     
    Rem ---------------------- Copyright ----------------------------------
    
    :: Code par BeFa, ne pas copier, modifier, distribuer ce code sans mon autorisation
    :: Ne pas supprimer ce Copyright, merci.
    
    Rem ---------------------- Copyright ----------------------------------
    
    
    (echo.
    echo  ^|==================================================================^|
    echo  ^|                  Fichier Récents                                 ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Microsoft\Windows\Recent\%%a - Supprimé>>log.txt))
    (echo  ^|==================================================================^|
    echo  ^|                  Fichiers Windows Temporaires                    ^|
    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\ - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\%%a\ - Supprimé>>log.txt))
    for /f "delims=" %%a in ('dir /B %tmp%') do (
      del /F /S /Q "%tmp%\%%a"
      if exist "%temp%\%%a" (echo  ^|%tmp%\%%a - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\%%a - Supprimé>>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\ - [Verrouillé]>>log.txt) else (echo  ^|%windir%\Temp\%%a\ - Supprimé>>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 - [Verrouillé]>>log.txt) else (echo  ^|%windir%\Temp\%%a - Supprimé>>log.txt))
    (echo  ^|==================================================================^|
    echo  ^|                  Fichiers Internet Temporaires                   ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - Supprimé>>log.txt))
    if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini" (
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini - Supprimé>>log.txt))
    if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat" (
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\dindex.dat" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat - Supprimé>>log.txt))
    for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Fichiers Internet temporaires\Content.IE5\"') do (
      attrib -H -S -D -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini - Supprimé>>log.txt)
      for /f "delims=" %%b in ('dir /B "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"') do (
        attrib -A -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b"
        DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b"
        set FIT=1
        if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b - Supprimé>>log.txt)))
    for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Fichiers Internet temporaires\Content.IE5\"') do (
      RMDIR /Q /S "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"
      set FIT=1
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\ - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\ - Supprimé>>log.txt))
    if "%FIT%"=="0" echo  ^|>>log.txt
    (echo  ^|==================================================================^|
    echo  ^|                  Cookies Windows                                 ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Microsoft\Windows\Cookies\%%a - Supprimé>>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\ - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Microsoft\Windows\Cookies\ - Supprimé>>log.txt))
    if "%cook%"=="0" echo  ^|>>log.txt
    (echo  ^|==================================================================^|
    echo  ^|                  Fichiers Prefetch                               ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%WINDIR%\Prefetch\%%a - Supprimé>>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  ^|                  Cache Mozilla Firefox                           ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Mozilla\Firefox\Profiles\%prof%\downloads.sqlite - Supprimé>>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\ - [Verrouillé]>>log.txt) else (echo  ^|%profile%\%%a\ - Supprimé>>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 - [Verrouillé]>>log.txt) else (echo  ^|%profile%\%var%\%%a - Supprimé>>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\ - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Macromedia\Flash Player\#SharedObjects\%%a\%%b\ - Supprimé>>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\ - [Verrouillé]>>log.txt) else (echo  ^|%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\%%a\ - Supprimé>>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 - [Verrouillé]>>log.txt) else (echo  ^|%programdata%\Microsoft\Windows Defender\Scans\History\Results\Resource\%%a - Supprimé>>log.txt))
    if "%wdef%"=="0" echo  ^|>>log.txt
    start log.txt


    Donc, il supprime :
    Fichier Récents
    Fichiers Windows Temporaires
    Cookies Windows
    Fichiers Prefetch
    Cache Mozilla Firefox
    Macromedia Flash Player
    Windows Defender


    Et pour les Fichiers Internet Temporaires (Temporary Internet Files), en fait, je n'arrive pas à les supprimer réellement, c'est juste une liste.
    Ils se suppriment de l'explorateur Windows, mais il suffit de passer un CCleaner pour voir que ces fichiers temporaires sont toujours là.

    Donc, je bosse encore sur un programme pour les supprimer complètement du disque sans passer par un programme tiers.
    Voici où j'en suis pour les fichiers temporaires, peut être ça peut t'aider, mais comme je te l'ai dit, cela ne les supprime pas du disque :

    @echo off
    
    (echo  ^|==================================================================^|
    echo  ^|                  Fichiers Internet Temporaires                   ^|
    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 - [Verrouillé]>>log.txt) else (echo  ^|%localappdata%\Microsoft\Windows\Temporary Internet Files\AntiPhishing\%%a - Supprimé>>log.txt))
    if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini" (
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\desktop.ini - Supprimé>>log.txt))
    if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat" (
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\dindex.dat" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\index.dat - Supprimé>>log.txt))
    for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Fichiers Internet temporaires\Content.IE5\"') do (
      attrib -H -S -D -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"
      attrib -H -S -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini"
      DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini"
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\desktop.ini - Supprimé>>log.txt)
      for /f "delims=" %%b in ('dir /B "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"') do (
        attrib -A -I "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b"
        DEL /F /Q "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b"
        set FIT=1
        if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\%%b - Supprimé>>log.txt)))
    for /f "delims=" %%a in ('dir /A:D /B "%tmp%\Fichiers Internet temporaires\Content.IE5\"') do (
      RMDIR /Q /S "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\"
      set FIT=1
      if exist "%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\" (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\ - [Verrouillé]>>log.txt) else (echo  ^|%tmp%\Fichiers Internet temporaires\Content.IE5\%%a\ - Supprimé>>log.txt))
    if "%FIT%"=="0" echo  ^|>>log.txt
    
    start log.txt
    1
    1. alias
       
      topppppppppppp
      0
    2. SALSABYL2018 Messages postés 1 Date d'inscription   Statut Membre Dernière intervention  
       
      TOPPPPP !!! Un grand travail d'informaticien ! Chapeau !
      0
  2. greg1107 Messages postés 71 Statut Membre 2
     
    Franchement un grand merci, ça fait super plaisir!
    C'est du beau boulot !
    :) yeah Rock'n'roll et soleil to you !;)

    je continue donc toujours à chercher pour Vista , server 2003 et server 2008 !

    Donc nettoyage en batch et plus complet SVP. :)

    BeFaX you are the best ! ;)

    to code or not code that is the question!

    greg1107
    0