FocusedWolf

Windows 10: Cleanup.bat

Apr 4th, 2019 (edited)
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 55.86 KB | None | 0 0
  1. @echo off
  2. REM Version 46
  3. title Cleanup
  4. color 02
  5.  
  6. :CheckPermissions
  7.     fltmc >nul 2>&1 || (
  8.         echo Requesting administrative privileges...
  9.         start cmd /c powershell.exe -Command "Start-Process cmd -Verb runas -ArgumentList '/c \"\"%~s0\"\" %*'"
  10.         exit /b 0
  11.     )
  12.  
  13. REM This file is used to clean Windows, Steam, and various other programs.
  14. REM
  15. REM NOTE: Before using this script, you need to run this command at least once to configure what gets cleaned by Disk Cleanup when its called by the script:
  16. REM $ cleanmgr /sageset:1
  17.  
  18. REM http://www.codeproject.com/Tips/119828/Running-a-bat-file-as-administrator-Correcting-cur
  19. setlocal enableextensions enabledelayedexpansion
  20. cd /d "%~dp0"
  21.  
  22. if /i "%~1" == "nopause" (
  23.     set NOPAUSE=1
  24. ) else (
  25.     set NOPAUSE=0
  26. )
  27.  
  28. if /i "%~2" == "simplecleaning" (
  29.     set SIMPLECLEANING=1
  30. ) else (
  31.     set SIMPLECLEANING=0
  32. )
  33.  
  34. if /i "%~2" == "normalcleaning" (
  35.     set NORMALCLEANING=1
  36. ) else (
  37.     set NORMALCLEANING=0
  38. )
  39.  
  40. if /i "%~2" == "fullcleaning" (
  41.     set FULLCLEANING=1
  42. ) else (
  43.     set FULLCLEANING=0
  44. )
  45.  
  46. :Choice
  47.     set CLEAN_UNIX_FILES=0
  48.     set CLEAN_EVENT_LOG=0
  49.     set RUN_SYSTEM_FILE_CHECKER_TOOL=0
  50.     set RUN_STEAM_REPAIR_TOOL=0
  51.  
  52.     REM set RUN_CLEANMGR=1
  53.    REM Disabled so i could move the code to DiskCleanup.bat.
  54.    REM Didn't see a reason to delete it though.
  55.     set RUN_CLEANMGR=0
  56.  
  57.     if /i "%SIMPLECLEANING%" equ "1" (
  58.         set CLEAN_UNIX_FILES=0
  59.         set CLEAN_EVENT_LOG=0
  60.         set RUN_SYSTEM_FILE_CHECKER_TOOL=0
  61.         set RUN_STEAM_REPAIR_TOOL=0
  62.         set RUN_CLEANMGR=0
  63.         goto :Work
  64.     )
  65.  
  66.     if /i "%NORMALCLEANING%" equ "1" (
  67.         set CLEAN_UNIX_FILES=0
  68.         set CLEAN_EVENT_LOG=1
  69.         set RUN_SYSTEM_FILE_CHECKER_TOOL=0
  70.         set RUN_STEAM_REPAIR_TOOL=0
  71.  
  72.         REM set RUN_CLEANMGR=1
  73.        REM Disabled so i could move the code to DiskCleanup.bat.
  74.        REM Didn't see a reason to delete it though.
  75.         set RUN_CLEANMGR=0
  76.  
  77.         goto :Work
  78.     )
  79.  
  80.     if /i "%FULLCLEANING%" equ "1" (
  81.         set CLEAN_UNIX_FILES=0
  82.         set CLEAN_EVENT_LOG=1
  83.         set RUN_SYSTEM_FILE_CHECKER_TOOL=1
  84.         set RUN_STEAM_REPAIR_TOOL=1
  85.  
  86.         REM set RUN_CLEANMGR=1
  87.        REM Disabled so i could move the code to DiskCleanup.bat.
  88.        REM Didn't see a reason to delete it though.
  89.         set RUN_CLEANMGR=0
  90.  
  91.         goto :Work
  92.     )
  93.  
  94. :PROMPT_ONE
  95.     cls
  96.     set /p CLEAN_UNIX_FILES=Clean macOS and Linux metadata [0^|1]:
  97.     if /i "%CLEAN_UNIX_FILES%" equ "0" goto :PROMPT_TWO
  98.     if /i "%CLEAN_UNIX_FILES%" equ "1" goto :PROMPT_TWO
  99.     goto :PROMPT_ONE
  100. :PROMPT_TWO
  101.     cls
  102.     set /p CLEAN_EVENT_LOG=Clean Event Log [0^|1]:
  103.     if /i "%CLEAN_EVENT_LOG%" equ "0" goto :PROMPT_THREE
  104.     if /i "%CLEAN_EVENT_LOG%" equ "1" goto :PROMPT_THREE
  105.     goto :PROMPT_TWO
  106. :PROMPT_THREE
  107.     cls
  108.     set /p RUN_SYSTEM_FILE_CHECKER_TOOL=Run System File Checker tool [0^|1]:
  109.     if /i "%RUN_SYSTEM_FILE_CHECKER_TOOL%" equ "0" goto :PROMPT_FOUR
  110.     if /i "%RUN_SYSTEM_FILE_CHECKER_TOOL%" equ "1" goto :PROMPT_FOUR
  111.     goto :PROMPT_THREE
  112. :PROMPT_FOUR
  113.     cls
  114.     set /p RUN_STEAM_REPAIR_TOOL=Run Steam Repair tool [0^|1]:
  115.     if /i "%RUN_STEAM_REPAIR_TOOL%" equ "0" goto :Work
  116.     if /i "%RUN_STEAM_REPAIR_TOOL%" equ "1" goto :Work
  117.     goto :PROMPT_FOUR
  118.  
  119. :CleanUnixFiles
  120.     setlocal
  121.  
  122.     REM macOS crap removal.
  123.    REM SOURCE: https://ardamis.com/2010/08/10/clean-up-those-mac-osx-hidden-files/
  124.  
  125.     if /i "%CLEAN_UNIX_FILES%" equ "1" (
  126.        REM I took out C because why do Windows and AppData?
  127.         for %%I in (D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%I:\ (
  128.             dir "%%I:\" > nul 2>&1
  129.             if !errorlevel! equ 0 (
  130.                 echo.
  131.                 echo Removing macOS and Linux metadata from drive: %%I:\
  132.  
  133.                 cd /d %%I:\
  134.  
  135.                 REM http://en.wikipedia.org/wiki/Resource_fork
  136.                 del /f /s /q /a ._*
  137.  
  138.                 REM http://en.wikipedia.org/wiki/.DS_Store
  139.                 del /f /s /q /a .DS_Store
  140.  
  141.                 rd /s /q .fseventsd
  142.                 rd /s /q .Spotlight-V100
  143.  
  144.                 REM http://en.wikipedia.org/wiki/Recycle_bin_(computing)
  145.                 rd /s /q .Trashes
  146.  
  147.                 REM Linux specific.
  148.                 rd /s /q .Trash-1000
  149.             )
  150.         )
  151.     )
  152.  
  153.     endlocal & goto :eof
  154.  
  155. :CleanChkdskFiles
  156.     setlocal
  157.  
  158.     REM When a boot-time Chkdsk runs it creates bootsqm.dat and bootTel.dat files on every scanned drive.
  159.    REM NOTE: I removed the /s option so it doesn't delete from subdirectories (which was causing a slow down). I think these files are only created at the top level of the drives.
  160.     for %%I in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  161.         if exist "%%I:\bootsqm.dat" (
  162.             del /f /s /q /a "%%I:\bootsqm.dat"
  163.         )
  164.  
  165.         if exist "%%I:\bootTel.dat" (
  166.             del /f /s /q /a "%%I:\bootTel.dat"
  167.         )
  168.     )
  169.  
  170.     endlocal & goto :eof
  171.  
  172. :CleanAdobe
  173.     setlocal
  174.  
  175.     for /d %%D in ("%AppData%\Adobe\CCX Welcome\*") do rd /s /q "%%D"
  176.     del /f /s /q /a "%AppData%\Adobe\CCX Welcome\*"
  177.  
  178.     for /d %%D in ("%AppData%\Adobe\Common\Peak Files\*") do rd /s /q "%%D"
  179.     del /f /s /q /a "%AppData%\Adobe\Common\Peak Files\*"
  180.  
  181.     for /d %%D in ("%AppData%\Adobe\Common\Media Cache\*") do rd /s /q "%%D"
  182.     del /f /s /q /a "%AppData%\Adobe\Common\Media Cache\*"
  183.  
  184.     for /d %%D in ("%AppData%\Adobe\Common\Media Cache Files\*") do rd /s /q "%%D"
  185.     del /f /s /q /a "%AppData%\Adobe\Common\Media Cache Files\*"
  186.  
  187.     endlocal & goto :eof
  188.  
  189. :CleanOkular
  190.     setlocal
  191.  
  192.     REM Delete the okular settings directory which contains recent-file data in the "\docdata" subdirectory.
  193.     rd /s /q "%LocalAppData%\okular"
  194.  
  195.     REM Delete the okular settings file which contains a recent-files list.
  196.     del /f /s /q /a "%LocalAppData%\okularrc"
  197.  
  198.     endlocal & goto :eof
  199.  
  200. :CleanOneNote
  201.     setlocal
  202.  
  203.     for /d %%D in ("%LocalAppData%\Microsoft\OneNote\16.0\*") do rd /s /q "%%D"
  204.     del /f /s /q /a "%LocalAppData%\Microsoft\OneNote\16.0\*"
  205.  
  206.     endlocal & goto :eof
  207.  
  208. :CleanMirc
  209.     setlocal
  210.  
  211.     for /d %%D in ("%AppData%\mIRC\logs\*") do rd /s /q "%%D"
  212.     del /f /s /q /a "%AppData%\mIRC\logs\*"
  213.  
  214.     endlocal & goto :eof
  215.  
  216. :CleanAtom
  217.     setlocal
  218.  
  219.     REM Remove old versions.
  220.     set directory=%LocalAppData%\atom
  221.     set pathname="%directory%\app-*"
  222.     set LatestVersionPath=""
  223.     for /f %%d in ('dir %pathname% /b /a:d /o:d') do set LatestVersionPath="%directory%\%%d"
  224.     if /i not %LatestVersionPath%=="" (
  225.        REM echo Latest version detected: %LatestVersionPath%
  226.         for /f %%d in ('dir %pathname% /b /a:d /o:d') do (
  227.             if /i not "%directory%\%%d"==%LatestVersionPath% (
  228.                 echo Removing old version: "%directory%\%%d"
  229.                 rd /s /q "%directory%\%%d"
  230.             )
  231.         )
  232.     )
  233.  
  234.     endlocal & goto :eof
  235.  
  236. :CleanDiscord
  237.     setlocal
  238.  
  239.     for /d %%D in ("%AppData%\Discord\Cache\*") do rd /s /q "%%D"
  240.     del /f /s /q /a "%AppData%\Discord\Cache\*"
  241.  
  242.     REM Remove old versions.
  243.     set directory=%LocalAppData%\Discord
  244.     set pathname="%directory%\app-*"
  245.     set LatestVersionPath=""
  246.     for /f %%d in ('dir %pathname% /b /a:d /o:d') do set LatestVersionPath="%directory%\%%d"
  247.     if /i not %LatestVersionPath%=="" (
  248.        REM echo Latest version detected: %LatestVersionPath%
  249.         for /f %%d in ('dir %pathname% /b /a:d /o:d') do (
  250.             if /i not "%directory%\%%d"==%LatestVersionPath% (
  251.                 echo Removing old version: "%directory%\%%d"
  252.                 rd /s /q "%directory%\%%d"
  253.             )
  254.         )
  255.     )
  256.  
  257.     endlocal & goto :eof
  258.  
  259. :CleanVirtualBox
  260.     setlocal
  261.  
  262.     for /d %%D in ("%LocalAppData%\VirtualBox Dropped Files\*") do rd /s /q "%%D"
  263.     del /f /s /q /a "%LocalAppData%\VirtualBox Dropped Files\*"
  264.  
  265.     endlocal & goto :eof
  266.  
  267. :CleanVMware
  268.     setlocal
  269.  
  270.     for /d %%D in ("%LocalAppData%\VMware\*") do rd /s /q "%%D"
  271.     del /f /s /q /a "%LocalAppData%\VMware\*"
  272.  
  273.     endlocal & goto :eof
  274.  
  275. :CleanJetBrainsDotPeek
  276.     setlocal
  277.  
  278.     for /d %%D in ("%LocalAppData%\JetBrains\dotPeek\vAny\DecompilerCache\*") do rd /s /q "%%D"
  279.     del /f /s /q /a "%LocalAppData%\JetBrains\dotPeek\vAny\DecompilerCache\*"
  280.  
  281.     endlocal & goto :eof
  282.  
  283. :CleanVisualStudio
  284.     setlocal
  285.  
  286.     for /d %%D in ("%LocalAppData%\Microsoft\Web Platform Installer\installers\*") do rd /s /q "%%D"
  287.     del /f /s /q /a "%LocalAppData%\Microsoft\Web Platform Installer\installers\*"
  288.  
  289.     for /d %%D in ("%UserProfile%\.nuget\packages\*") do rd /s /q "%%D"
  290.     del /f /s /q /a "%UserProfile%\.nuget\packages\*"
  291.  
  292.     REM -----
  293.  
  294.     REM Scan for, and prompt for deletion of, "\TestResults" directories generated by unit-test projects.
  295.    REM for /d /r "D:\Users\Wolf\Files\Archives\Projects\Visual Studio" %%D in (*TestResults) do rd /s "%%D"
  296.  
  297.     REM For all "TestResults" folders in my "Visual Studio" projects directory:
  298.    REM     Delete all Deploy_Wolf folders in the TestResults folders.
  299.    REM     Delete the parent folder if it is empty.
  300.    REM echo. Searching to destroy Unit Test results in: D:\..\Visual Studio\..\..\TestResults
  301.  
  302.     REM for /d /r "D:\Users\Wolf\Files\Archives\Projects\Visual Studio" %%D in (*TestResults) do (
  303.    REM     echo.
  304.    REM     echo.Found: %%D
  305.  
  306.     REM     for /f "tokens=*" %%I in ('dir /b /a "%%D\Deploy_Wolf*"') do (
  307.    REM         echo. Deleting TestResult: "%%D\%%I"
  308.    REM         rd /s /q "%%D\%%I"
  309.    REM     )
  310.  
  311.     REM     dir /b /a "%%D\*" | >nul findstr . && (
  312.    REM         echo. * NOT deleting parent folder: Unknown files or folders found.
  313.    REM     ) || (
  314.    REM         echo. Deleting empty parent folder: "%%D"
  315.    REM         rd /s /q "%%D"
  316.    REM     )
  317.  
  318.     REM     echo.-----
  319.    REM )
  320.  
  321.     endlocal & goto :eof
  322.  
  323. :CleanVSCode
  324.     setlocal
  325.  
  326.     for /d %%D in ("%AppData%\Code\Cache\*") do rd /s /q "%%D"
  327.     del /f /s /q /a "%AppData%\Code\Cache\*"
  328.  
  329.     for /d %%D in ("%AppData%\Code\CachedData\*") do rd /s /q "%%D"
  330.     del /f /s /q /a "%AppData%\Code\CachedData\*"
  331.  
  332.     for /d %%D in ("%AppData%\Code\CachedExtensions\*") do rd /s /q "%%D"
  333.     del /f /s /q /a "%AppData%\Code\CachedExtensions\*"
  334.  
  335.     for /d %%D in ("%AppData%\Code\User\History\*") do rd /s /q "%%D"
  336.     del /f /s /q /a "%AppData%\Code\User\History\*"
  337.  
  338.     endlocal & goto :eof
  339.  
  340. :CleanNuGetCache
  341.     setlocal
  342.  
  343.     REM SOURCE: https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders
  344.  
  345.     REM Clear the 3.x+ cache (use either command)
  346.     dotnet nuget locals http-cache --clear
  347.    REM  nuget locals http-cache -clear
  348.  
  349.     REM Clear the 2.x cache (NuGet CLI 3.5 and earlier only)
  350.    REM  nuget locals packages-cache -clear
  351.  
  352.     REM Clear the global packages folder (use either command)
  353.     dotnet nuget locals global-packages --clear
  354.    REM  nuget locals global-packages -clear
  355.  
  356.     REM Clear the temporary cache (use either command)
  357.     dotnet nuget locals temp --clear
  358.    REM  nuget locals temp -clear
  359.  
  360.     REM Clear the plugins cache (use either command)
  361.     dotnet nuget locals plugins-cache --clear
  362.    REM  nuget locals plugins-cache -clear
  363.  
  364.     REM Clear all caches (use either command)
  365.     dotnet nuget locals all --clear
  366.    REM  nuget locals all -clear
  367.  
  368.     REM SOURCE: https://stackoverflow.com/questions/30933277/how-can-i-clear-the-nuget-package-cache-using-the-command-line?answertab=createdasc#tab-top
  369.     del /f /s /q /a "%LocalAppData%\NuGet\Cache\*"
  370.  
  371.     endlocal & goto :eof
  372.  
  373. :CleanSmartGit
  374.     setlocal
  375.  
  376.     REM Remove old versions.
  377.     set directory=%AppData%\syntevo\SmartGit
  378.    REM findstr lacks regex '+' operator so '[.0-9]+' expands to '[.0-9][.0-9]*'.
  379.     set pattern="[.0-9][.0-9]*$"
  380.     set LatestVersionPath=""
  381.     for /f %%d in ('dir "%directory%" /b /a:d /o:d ^| findstr %pattern%') do (
  382.         if %errorlevel% equ 0 (
  383.             set LatestVersionPath="%directory%\%%d"
  384.         )
  385.     )
  386.     if /i not %LatestVersionPath%=="" (
  387.        REM echo Latest version detected: %LatestVersionPath%
  388.         for /f %%d in ('dir "%directory%" /b /a:d /o:d ^| findstr %pattern%') do (
  389.             if /i not "%directory%\%%d"==%LatestVersionPath% (
  390.                 echo Removing old version: "%directory%\%%d"
  391.                 rd /s /q "%directory%\%%d"
  392.             )
  393.         )
  394.     )
  395.  
  396.     REM -----
  397.  
  398.     REM Remove old versions.
  399.     set directory=%ProgramData%\chocolatey\lib\smartgit\tools
  400.    REM findstr lacks regex '+' operator so '[0-9]+' expands to '[0-9][0-9]*'.
  401.     set pattern="[0-9][0-9_]*-setup\.exe$"
  402.     set LatestVersionPath=""
  403.     for /f %%f in ('dir "%directory%" /b /a:-d /o:d ^| findstr %pattern%') do (
  404.         if %errorlevel% equ 0 (
  405.             set LatestVersionPath="%directory%\%%f"
  406.         )
  407.     )
  408.     if /i not %LatestVersionPath%=="" (
  409.        REM echo Latest version detected: %LatestVersionPath%
  410.         for /f %%f in ('dir "%directory%" /b /a:-d /o:d ^| findstr %pattern%') do (
  411.             if /i not "%directory%\%%f"==%LatestVersionPath% (
  412.                 echo Removing old version: "%directory%\%%f"
  413.                 del /f /s /q /a "%directory%\%%f"
  414.             )
  415.         )
  416.     )
  417.  
  418.     endlocal & goto :eof
  419.  
  420. :CleanWindows
  421.     setlocal
  422.  
  423.     REM -----
  424.  
  425.     if /i "%RUN_CLEANMGR%" equ "1" (
  426.        REM NOTE: Run [$ Cleanmgr /sageset:1] to configure the set of items Cleanmgr will clean when started like this.
  427.         start "" /wait Cleanmgr /sagerun:1
  428.     )
  429.  
  430.     REM -----
  431.  
  432.     REM Run the System File Checker tool.
  433.    REM SOURCE: https://support.microsoft.com/en-us/help/929833/use-the-system-file-checker-tool-to-repair-missing-or-corrupted-system
  434.    REM SOURCE: https://answers.microsoft.com/en-us/windows/forum/all/event-viewer-error-when-creating-custom-view/dcf3203b-0258-4621-a724-1a674a702472
  435.     if /i "%RUN_SYSTEM_FILE_CHECKER_TOOL%" equ "1" (
  436.         Dism /Online /Cleanup-Image /Scanhealth
  437.         Dism /Online /Cleanup-Image /Restorehealth
  438.         sfc /scannow
  439.         echo.
  440.     )
  441.  
  442.     REM -----
  443.  
  444.     REM WinSxS cleanup.
  445.  
  446.     REM SOURCE: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/clean-up-the-winsxs-folder
  447.    REM SOURCE: https://answers.microsoft.com/en-us/windows/forum/all/is-it-safe-dism-online-cleanup-image-spsuperseded/5efb8e9c-0d13-45d8-9b11-38abe61c9828
  448.    REM SOURCE: https://blogs.technet.microsoft.com/askpfeplat/2014/05/13/how-to-clean-up-the-winsxs-directory-and-free-up-disk-space-on-windows-server-2008-r2-with-new-update/
  449.    REM SOURCE: https://www.maketecheasier.com/clean-component-store-windows10/
  450.    REM SOURCE: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/clean-up-the-winsxs-folder
  451.  
  452.     REM Displays information about the component store.
  453.     Dism /Online /Cleanup-Image /AnalyzeComponentStore
  454.  
  455.     REM Cleanup service pack backup files
  456.     Dism /Online /Cleanup-Image /SpSuperseded
  457.  
  458.     REM Deletes previous versions of updated components.
  459.    REM StartComponentCleanup also exists as a Task Scheduler task that runs every 30 days on startup, so instead of waiting 30 days for cleanup you can delete that crap now.
  460.    REM "Using the /StartComponentCleanup parameter of Dism.exe on a running version of Windows 10 or later gives you similar results to running the StartComponentCleanup task in Task Scheduler,
  461.    REM except previous versions of updated components will be immediately deleted (without a 30 day grace period) and you will not have a 1-hour timeout limitation.": https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/clean-up-the-winsxs-folder
  462.     Dism /Online /Cleanup-Image /StartComponentCleanup
  463.  
  464.     REM Removes all superseded versions of every component in the component store.
  465.    REM Using this option removes the ability to uninstall the latest update.
  466.    REM This cleaned the 9000+ files i had in C:\Windows\WinSxS\Temp\PendingRenames\
  467.     Dism /online /Cleanup-Image /StartComponentCleanup /ResetBase
  468.  
  469.     REM -----
  470.  
  471.     REM M$ is slow to fix the MMC error in event viewer. This is a workaround.
  472.    REM SOURCE: https://www.bleepingcomputer.com/news/microsoft/windows-10-v1903-v1809-updates-break-event-viewer-custom-views/
  473.    REM SOURCE: https://www.winhelponline.com/blog/windows-10-v1903-19h1-is-available-now/#eventvwr
  474.     icacls "%ProgramData%\Microsoft\Event Viewer\Views\view_*.xml" /grant administrators:RX
  475.     icacls "%ProgramData%\Microsoft\Event Viewer\Views\view_*.xml" /inheritance:r
  476.    REM To revert the .xml file permissions to default, run this command:
  477.    REM icacls "%ProgramData%\Microsoft\Event Viewer\Views\view_*.xml" /reset
  478.  
  479.     REM -----
  480.  
  481.     REM Rebuild Windows Management Instrumentation service files.
  482.    REM SOURCE: https://www.reddit.com/r/GlobalOffensive/comments/brgvlw/i_finally_fixed_my_csgo_game_freezes_fps_drops_it/
  483.  
  484.     for /l %%x in (0,1,5) do (
  485.         sc config winmgmt start= disabled
  486.         net stop winmgmt /y
  487.         sc query winmgmt | find /i "running"
  488.         if !errorlevel! equ 1 (
  489.             echo Windows Management Instrumentation service was successfully stopped...
  490.             echo.
  491.             del /f /s /q /a "%WinDir%\System32\wbem\Repository\*"
  492.             goto :DoneDeletingWMIRepository
  493.         )
  494.  
  495.         echo.
  496.         echo Windows Management Instrumentation service still running...
  497.         echo.
  498.         timeout 1 > nul
  499.     )
  500. :DoneDeletingWMIRepository
  501.     set count=0
  502.     for %%A in (%WinDir%\System32\wbem\Repository\*) do set /a count+=1
  503.  
  504.     if /i "%count%" GTR "0" (
  505.         echo.
  506.         echo ERROR: Windows Management Instrumentation service prevented deletion of repository files.
  507.         echo %count% files were not deleted.
  508.         echo.
  509.     )
  510.  
  511.     sc query winmgmt | find /i "running"
  512.     if !errorlevel! equ 1 (
  513.         echo.
  514.         echo Restarting Windows Management Instrumentation service...
  515.         echo.
  516.         sc config winmgmt start= auto
  517.         net start winmgmt
  518.     )
  519.  
  520.     REM -----
  521.  
  522.     REM Clean logs.
  523.    REM SOURCE: https://www.technipages.com/files-folders-you-can-safely-delete-in-windows-10
  524.    REM SOURCE: https://forum.piriform.com/topic/34206-please-default-to-not-clean-windows-log-files/
  525.  
  526.     attrib -r -s -h "%WinDir%\Debug\*" /s /d
  527.     for /d %%D in ("%WinDir%\Debug\*") do rd /s /q "%%D"
  528.     del /f /s /q /a "%WinDir%\Debug\*"
  529.  
  530.     attrib -r -s -h "%WinDir%\Logs\*" /s /d
  531.     for /d %%D in ("%WinDir%\Logs\*") do rd /s /q "%%D"
  532.     del /f /s /q /a "%WinDir%\Logs\*"
  533.  
  534.     del /f /s /q /a "%WinDir%\inf\*.log"
  535.     del /f /s /q /a "%WinDir%\Microsoft.NET\*.log"
  536.     del /f /s /q /a "%WinDir%\Panther\*.log"
  537.     del /f /s /q /a "%WinDir%\security\logs\*.log"
  538.     del /f /s /q /a "%WinDir%\security\logs\*.old"
  539.     del /f /s /q /a "%WinDir%\ServiceProfiles\LocalService\AppData\*.log"
  540.     del /f /s /q /a "%WinDir%\ServiceProfiles\NetworkService\AppData\*.log"
  541.     del /f /s /q /a "%WinDir%\SoftwareDistribution\*.log"
  542.    REM NOTE: These lack /s so they are not recursive and only delete explicitly from safe-according-to-the-internet locations inside %WinDir%.
  543.    REM With /s these could delete things from every subdirectory of %WinDir%\ which might be dangerous.
  544.     del /f /s /q /a "%WinDir%\*.bak"
  545.     del /f /s /q /a "%WinDir%\*.log"
  546.     del /f /s /q /a "%WinDir%\*log.txt"
  547.  
  548.     REM Some files will give access-denied when you try to delete them but i found about 250 files that could be deleted.
  549.     attrib -r -s -h "%ProgramData%\USOShared\Logs\*" /s /d
  550.     for /d %%D in ("%ProgramData%\USOShared\Logs\*") do rd /s /q "%%D"
  551.     del /f /s /q /a "%ProgramData%\USOShared\Logs\*"
  552.  
  553.     REM -----
  554.  
  555.     REM Clean crash dumps and error reports.
  556.  
  557.     for /d %%D in ("%WinDir%\Minidump\*") do rd /s /q "%%D"
  558.     del /f /s /q /a "%WinDir%\Minidump\*"
  559.  
  560.     del /f /s /q /a "%WinDir%\*.mdmp"
  561.     del /f /s /q /a "%WinDir%\*.dmp"
  562.     del /f /s /q /a "%ProgramData%\*.mdmp"
  563.     del /f /s /q /a "%ProgramData%\*.dmp"
  564.  
  565.     for /d %%D in ("%ProgramData%\Microsoft\Windows\WER\*") do rd /s /q "%%D"
  566.     del /f /s /q /a "%ProgramData%\Microsoft\Windows\WER\*"
  567.  
  568.     REM -----
  569.  
  570.     attrib -r -s -h "%WinDir%\Prefetch\*" /s /d
  571.     for /d %%D in ("%WinDir%\Prefetch\*") do rd /s /q "%%D"
  572.     del /f /s /q /a "%WinDir%\Prefetch\*"
  573.  
  574.     REM -----
  575.  
  576.     REM Clean temp files.
  577.  
  578.     attrib -r -s -h "%WinDir%\Temp\*" /s /d
  579.     for /d %%D in ("%WinDir%\Temp\*") do rd /s /q "%%D"
  580.     del /f /s /q /a "%WinDir%\Temp\*"
  581.  
  582.     attrib -r -s -h "%ProgramData%\Temp\*" /s /d
  583.     for /d %%D in ("%ProgramData%\Temp\*") do rd /s /q "%%D"
  584.     del /f /s /q /a "%ProgramData%\Temp\*"
  585.  
  586.     REM -----
  587.  
  588.     REM Delete all files in %WinDir%\SoftwareDistribution\Download\ and C:\WUDownloadCache\
  589.     net stop wuauserv /y
  590.     net stop bits /y
  591.  
  592.     for /d %%D in ("%WinDir%\SoftwareDistribution\Download\*") do rd /s /q "%%D"
  593.     del /f /s /q /a "%WinDir%\SoftwareDistribution\Download\*"
  594.  
  595.     for /d %%D in ("C:\WUDownloadCache\*") do rd /s /q "%%D"
  596.     del /f /s /q /a "C:\WUDownloadCache\*"
  597.  
  598.     net start wuauserv
  599.     net start bits
  600.  
  601.     REM -----
  602.  
  603.     REM Clean Event Logs.
  604.    REM SOURCE: based on https://www.tenforums.com/tutorials/16588-clear-all-event-logs-event-viewer-windows-4.html
  605.  
  606.     if /i "%CLEAN_EVENT_LOG%" equ "1" (
  607.         net stop NcdAutoSetup /y
  608.         net stop netprofm /y
  609.         net stop NlaSvc /y
  610.         net stop EventLog /y
  611.  
  612.         del /f /s /q /a "%WinDir%\System32\winevt\Logs\*"
  613.  
  614.         net start EventLog
  615.         net start NlaSvc
  616.         net start netprofm
  617.         net start NcdAutoSetup
  618.  
  619.         timeout /t 5
  620.  
  621.         for /f "tokens=*" %%g in ('wevtutil.exe el') do (
  622.             echo clearing "%%g"
  623.             wevtutil.exe cl "%%g"
  624.         )
  625.  
  626.         echo.
  627.         echo Event Logs have been cleared.
  628.         echo.
  629.     )
  630.  
  631.     REM -----
  632.  
  633.     REM Update Clock.
  634.  
  635.     net start w32time
  636.  
  637.     w32tm.exe /query /status /verbose
  638.  
  639.     w32tm.exe /config /manualpeerlist:"time.nist.gov pool.ntp.org" /syncfromflags:manual /update
  640.     w32tm.exe /resync
  641.  
  642.     w32tm.exe /query /status /verbose
  643.  
  644.     REM -----
  645.  
  646.     REM Clean ARP Cache.
  647.  
  648.     arp -a
  649.     netsh interface ip delete arpcache
  650.     arp -a
  651.  
  652.     REM -----
  653.  
  654.     REM Flush AppCompatCache
  655.  
  656.     rundll32.exe kernel32.dll,BaseFlushAppcompatCache
  657.  
  658.     REM -----
  659.  
  660.     endlocal & goto :eof
  661.  
  662. :CleanWindowsUserData
  663.     setlocal
  664.  
  665.     REM taskkill /f /im explorer.exe
  666.    REM timeout /t 5
  667.  
  668.     REM Clear File Explorer History in Windows 10
  669.    REM SOURCE: https://www.tenforums.com/tutorials/6712-clear-file-explorer-history-windows-10-a.html#option2
  670.     del /f /s /q /a "%AppData%\Microsoft\Windows\Recent\*"
  671.     del /f /s /q /a "%AppData%\Microsoft\Windows\Recent\AutomaticDestinations\*"
  672.     del /f /s /q /a "%AppData%\Microsoft\Windows\Recent\CustomDestinations\*"
  673.  
  674.     REM TODO: An all-users limitation here because it only cleans for the current user
  675.     reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" /va /f
  676.     reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths" /va /f
  677.  
  678.     REM timeout /t 5
  679.    REM start explorer.exe
  680.  
  681.     REM -----
  682.  
  683.     REM Clean logs (User Specific).
  684.    REM SOURCE: https://www.technipages.com/files-folders-you-can-safely-delete-in-windows-10
  685.    REM SOURCE: https://forum.piriform.com/topic/34206-please-default-to-not-clean-windows-log-files/
  686.  
  687.     del /f /s /q /a "%LocalAppData%\Microsoft\Windows\*.log"
  688.     del /f /s /q /a "%AppData%\..\LocalLow\Microsoft\Windows\*.log"
  689.     del /f /s /q /a "%AppData%\Microsoft\Windows\*.log"
  690.  
  691.     REM -----
  692.  
  693.     REM Clean crash dumps and error reports (User Specific).
  694.  
  695.     for /d %%D in ("%LocalAppData%\CrashDumps\*") do rd /s /q "%%D"
  696.     del /f /s /q /a "%LocalAppData%\CrashDumps\*"
  697.  
  698.     REM Delete all .dmp files in app subdirectories
  699.     del /f /s /q /a "%LocalAppData%\Packages\*.dmp"
  700.  
  701.     for /d %%D in ("%LocalAppData%\Microsoft\Windows\WER\*") do rd /s /q "%%D"
  702.     del /f /s /q /a "%LocalAppData%\Microsoft\Windows\WER\*"
  703.  
  704.     REM -----
  705.  
  706.     REM Clean temp files (User Specific).
  707.  
  708.     REM %Temp% is an alias for %LocalAppData%\Temp
  709.    REM attrib -r -s -h "%Temp%\*" /s /d
  710.    REM for /d %%D in ("%Temp%\*") do rd /s /q "%%D"
  711.    REM del /f /s /q /a "%Temp%\*"
  712.  
  713.     REM NOTE: If running these commands manually in cmd then replace %%D with %D.
  714.  
  715.     attrib -r -s -h "%LocalAppData%\Temp\*" /s /d
  716.     for /d %%D in ("%LocalAppData%\Temp\*") do rd /s /q "%%D"
  717.     del /f /s /q /a "%LocalAppData%\Temp\*"
  718.  
  719.     attrib -r -s -h "%AppData%\..\LocalLow\Temp\*" /s /d
  720.     for /d %%D in ("%AppData%\..\LocalLow\Temp\*") do rd /s /q "%%D"
  721.     del /f /s /q /a "%AppData%\..\LocalLow\Temp\*"
  722.  
  723.     attrib -r -s -h "%AppData%\Temp\*" /s /d
  724.     for /d %%D in ("%AppData%\Temp\*") do rd /s /q "%%D"
  725.     del /f /s /q /a "%AppData%\Temp\*"
  726.  
  727.     REM -----
  728.  
  729.     REM Stop Scheduledtask.
  730.     schtasks /end /tn "\Microsoft\Windows\Wininet\CacheTask"
  731.  
  732.     net stop COMSysApp /y
  733.     taskkill /f /im dllhost.exe
  734.     taskkill /f /im taskhost.exe
  735.     taskkill /f /im taskhostex.exe
  736.  
  737.     for /d %%D in ("%LocalAppData%\Microsoft\Windows\INetCache\*") do rd /s /q "%%D"
  738.     del /f /s /q /a "%LocalAppData%\Microsoft\Windows\INetCache\*"
  739.  
  740.     del /f /s /q /a "%LocalAppData%\Microsoft\Windows\WebCache\*"
  741.  
  742.     net start COMSysApp
  743.  
  744.     REM -----
  745.  
  746.     endlocal & goto :eof
  747.  
  748. :CleanNVIDIA
  749.     setlocal
  750.  
  751.     REM Remove Nvidia installer cache files left over by Nvidia after driver install.
  752.    REM http://nvidia.custhelp.com/app/answers/detail/a_id/3333/%7E/disk-space-used-when-installing-nvidia-drivers
  753.    REM Deletion of the Installer2 folder will not affect any of your currently installed NVIDIA drivers or software.
  754.    REM At most, it will prevent complete installs from occurring in the case of using an older driver from the OS driver store.
  755.    REM
  756.    REM Q: I've performed a "clean install" and then uninstalled the drivers from my system, but files remain in the Installer2 folder.
  757.    REM A: It is likely that you have performed some combination of multiple install/over-install/uninstall cycles and files from older drivers
  758.    REM are left in the folder. The "clean install" removes only the current driver files before installing the new driver.
  759.    REM In this case, the simplest way to remove the files is to delete the Installer2 folder.
  760.     attrib -r -s -h "%ProgramFiles%\NVIDIA Corporation\Installer2\*" /s /d
  761.     for /d %%D in ("%ProgramFiles%\NVIDIA Corporation\Installer2\*") do rd /s /q "%%D"
  762.     del /f /s /q /a "%ProgramFiles%\NVIDIA Corporation\Installer2\*"
  763.  
  764.     REM Delete Nvidia crash dumps.
  765.     attrib -r -s -h "%ProgramData%\NVIDIA Corporation\CrashDumps\*" /s /d
  766.     for /d %%D in ("%ProgramData%\NVIDIA Corporation\CrashDumps\*") do rd /s /q "%%D"
  767.     del /f /s /q /a "%ProgramData%\NVIDIA Corporation\CrashDumps\*"
  768.  
  769.     REM Delete Nvidia driver downloads.
  770.    REM SOURCE: https://www.howtogeek.com/342322/why-does-nvidia-store-gigabytes-of-installer-files-on-your-hard-drive/
  771.     for /d %%D in ("%ProgramData%\NVIDIA Corporation\Downloader\*") do rd /s /q "%%D"
  772.     del /f /s /q /a "%ProgramData%\NVIDIA Corporation\Downloader\*"
  773.  
  774.     REM -----
  775.  
  776.     REM Clean Nvidia caches (User Specific).
  777.  
  778.     REM Nvidia cache locations: https://www.reddit.com/r/EscapefromTarkov/comments/g06vzk/some_things_to_check_after_the_not_only_this_file/?utm_medium=android_app&utm_source=share
  779.  
  780.     for /d %%D in ("%AppData%\NVIDIA\ComputeCache\*") do rd /s /q "%%D"
  781.     del /f /s /q /a "%AppData%\NVIDIA\ComputeCache\*"
  782.  
  783.     for /d %%D in ("%LocalAppData%\D3DSCache\*") do rd /s /q "%%D"
  784.     del /f /s /q /a "%LocalAppData%\D3DSCache\*"
  785.  
  786.     for /d %%D in ("%LocalAppData%\NVIDIA Corporation\NV_cache\*") do rd /s /q "%%D"
  787.     del /f /s /q /a "%LocalAppData%\NVIDIA Corporation\NV_cache\*"
  788.  
  789.     for /d %%D in ("%LocalAppData%\NVIDIA\DXCache\*") do rd /s /q "%%D"
  790.     del /f /s /q /a "%LocalAppData%\NVIDIA\DXCache\*"
  791.  
  792.     for /d %%D in ("%LocalAppData%\NVIDIA\GLCache\*") do rd /s /q "%%D"
  793.     del /f /s /q /a "%LocalAppData%\NVIDIA\GLCache\*"
  794.  
  795.     for /d %%D in ("%ProgramData%\NVIDIA Corporation\NV_Cache\*") do rd /s /q "%%D"
  796.     del /f /s /q /a "%ProgramData%\NVIDIA Corporation\NV_Cache\*"
  797.  
  798.     for /d %%D in ("%UserProfile%\AppData\LocalLow\NVIDIA\PerDriverVersion\DXCache\*") do rd /s /q "%%D"
  799.     del /f /s /q /a "%UserProfile%\AppData\LocalLow\NVIDIA\PerDriverVersion\DXCache\*"
  800.  
  801.     REM -----
  802.  
  803.     endlocal & goto :eof
  804.  
  805. :CleanFirefox
  806.     setlocal
  807.  
  808.     REM Delete all .dmp and .extra files in firefox subdirectories
  809.     del /f /s /q /a "%AppData%\Mozilla\Firefox\*.dmp"
  810.     del /f /s /q /a "%AppData%\Mozilla\Firefox\*.extra"
  811.  
  812.     cd /d %LocalAppData%\Mozilla\Firefox\Profiles\**.default\
  813.     if !errorlevel! equ 0 (
  814.         for /f "delims=" %%i in ('dir cache2 /b') do (
  815.            REM Delete %%i if its a folder.
  816.             if exist "cache2\%%i\" (
  817.                 rd /s /q "cache2\%%i\"
  818.             )
  819.            REM Delete %%i if its a file.
  820.             if exist "cache2\%%i" (
  821.                 del /f /s /q /a "cache2\%%i"
  822.             )
  823.         )
  824.     )
  825.  
  826.     endlocal & goto :eof
  827.  
  828. :CleanWaterfox
  829.     setlocal
  830.  
  831.     REM Delete all .dmp and .extra files in waterfox subdirectories
  832.     del /f /s /q /a "%AppData%\Waterfox\*.dmp"
  833.     del /f /s /q /a "%AppData%\Waterfox\*.extra"
  834.  
  835.     cd /d %LocalAppData%\Waterfox\Profiles\**.default\
  836.     if !errorlevel! equ 0 (
  837.         for /f "delims=" %%i in ('dir cache2 /b') do (
  838.            REM Delete %%i if its a folder.
  839.             if exist "cache2\%%i\" (
  840.                 rd /s /q "cache2\%%i\"
  841.             )
  842.            REM Delete %%i if its a file.
  843.             if exist "cache2\%%i" (
  844.                 del /f /s /q /a "cache2\%%i"
  845.             )
  846.         )
  847.     )
  848.  
  849.     cd /d %LocalAppData%\Waterfox\Profiles\**.68-edition-default\
  850.     if !errorlevel! equ 0 (
  851.         for /f "delims=" %%i in ('dir cache2 /b') do (
  852.            REM Delete %%i if its a folder.
  853.             if exist "cache2\%%i\" (
  854.                 rd /s /q "cache2\%%i\"
  855.             )
  856.            REM Delete %%i if its a file.
  857.             if exist "cache2\%%i" (
  858.                 del /f /s /q /a "cache2\%%i"
  859.             )
  860.         )
  861.     )
  862.  
  863.     endlocal & goto :eof
  864.  
  865. :CleanLibreWolf
  866.     setlocal
  867.  
  868.     REM Delete all .dmp and .extra files in waterfox subdirectories
  869.     del /f /s /q /a "%AppData%\LibreWolf\*.dmp"
  870.     del /f /s /q /a "%AppData%\LibreWolf\*.extra"
  871.  
  872.     cd /d %LocalAppData%\LibreWolf\Profiles\**.default\
  873.     if !errorlevel! equ 0 (
  874.         for /f "delims=" %%i in ('dir cache2 /b') do (
  875.            REM Delete %%i if its a folder.
  876.             if exist "cache2\%%i\" (
  877.                 rd /s /q "cache2\%%i\"
  878.             )
  879.            REM Delete %%i if its a file.
  880.             if exist "cache2\%%i" (
  881.                 del /f /s /q /a "cache2\%%i"
  882.             )
  883.         )
  884.     )
  885.  
  886.     cd /d %LocalAppData%\LibreWolf\Profiles\**.dev-edition-default\
  887.     if !errorlevel! equ 0 (
  888.         for /f "delims=" %%i in ('dir cache2 /b') do (
  889.            REM Delete %%i if its a folder.
  890.             if exist "cache2\%%i\" (
  891.                 rd /s /q "cache2\%%i\"
  892.             )
  893.            REM Delete %%i if its a file.
  894.             if exist "cache2\%%i" (
  895.                 del /f /s /q /a "cache2\%%i"
  896.             )
  897.         )
  898.     )
  899.  
  900.     endlocal & goto :eof
  901.  
  902. :CleanEdge
  903.     setlocal
  904.  
  905.     REM Delete Edge cache files.
  906.     for /d %%D in ("%LocalAppData%\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\*") do rd /s /q "%%D"
  907.     del /f /s /q /a "%LocalAppData%\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\*"
  908.  
  909.     endlocal & goto :eof
  910.  
  911. :CleanGoogle
  912.     setlocal
  913.  
  914.     REM Delete all .dmp files in google subdirectories
  915.     del /f /s /q /a "%LocalAppData%\Google\*.dmp"
  916.  
  917.     REM Delete GoogleChrome cache
  918.     del /f /s /q /a "%LocalAppData%\Google\Chrome\User Data\Default\Cache\*"
  919.     del /f /s /q /a "%LocalAppData%\Google\Chrome\User Data\Default\Media Cache\*"
  920.  
  921.     REM Delete GoogleChrome site data
  922.     for /d %%D in ("%LocalAppData%\Google\Chrome\User Data\Default\File System\*") do rd /s /q "%%D"
  923.     del /f /s /q /a "%LocalAppData%\Google\Chrome\User Data\Default\File System\*"
  924.  
  925.     REM Delete GoogleEarth Cache
  926.     for /d %%D in ("%UserProfile%\AppData\locallow\Google\GoogleEarth\Cache\*") do rd /s /q "%%D"
  927.     del /f /s /q /a "%UserProfile%\AppData\locallow\Google\GoogleEarth\Cache\*"
  928.  
  929.     endlocal & goto :eof
  930.  
  931. :CleanDropbox
  932.     setlocal
  933.  
  934.     REM Delete all Dropbox log files
  935.     del /f /s /q /a "%ProgramData%\Dropbox\Update\Log"
  936.  
  937.     endlocal & goto :eof
  938.  
  939. :CleanOBS
  940.     setlocal
  941.  
  942.     REM Delete all OBS log files
  943.     del /f /s /q /a "%AppData%\obs-studio\logs"
  944.  
  945.     REM Delete all OBS crash files
  946.     del /f /s /q /a "%AppData%\obs-studio\crashes"
  947.  
  948.     endlocal & goto :eof
  949.  
  950. :CleanVLC
  951.     setlocal
  952.  
  953.     REM Delete VLC Cache
  954.     for /d %%D in ("%AppData%\vlc\crashdump\*") do rd /s /q "%%D"
  955.     del /f /s /q /a "%AppData%\vlc\crashdump\*"
  956.  
  957.     REM Delete VLC Art
  958.     for /d %%D in ("%AppData%\vlc\art\*") do rd /s /q "%%D"
  959.     del /f /s /q /a "%AppData%\vlc\art\*"
  960.  
  961.     endlocal & goto :eof
  962.  
  963. :CleanLibreOffice
  964.     setlocal
  965.  
  966.     REM Delete crash dumps
  967.     for /d %%d in ("%AppData%\LibreOffice\*") do (
  968.         if exist "%%d\crash\" (
  969.             rd /s /q "%%d\crash\"
  970.         )
  971.     )
  972.  
  973.     endlocal & goto :eof
  974.  
  975. :CleanSteam
  976.     setlocal
  977.  
  978.     REM ----- Kill Steam -----
  979.  
  980.     REM echo Attempting to close steam.exe gently
  981.    REM taskkill /im steam.exe >nul 2>&1
  982.    REM timeout /t 32
  983.  
  984.     echo Attempting to kill steam.exe if its still alive
  985.     taskkill /f /im steam.exe >nul 2>&1
  986.     timeout /t 3
  987.  
  988.     REM ----- Determine Steam directory -----
  989.  
  990.     REM SOURCE: https://stackoverflow.com/a/12071458/490748
  991.     set RegKey="HKEY_CURRENT_USER\Software\Valve\Steam"
  992.     set RegValue=SteamPath
  993.     for /f "usebackq skip=2 tokens=1-2*" %%i in (`reg query !RegKey! /v !RegValue!`) do (
  994.         set Name=%%i
  995.         set Type=%%j
  996.         set Data=%%k
  997.  
  998.         REM Get Steam's directory.
  999.         set SteamPath=!Data!
  1000.     )
  1001.  
  1002.     REM Change forward slash to back slash.
  1003.     set SteamPath=%SteamPath:/=\%
  1004.  
  1005.     REM Clean all Steam folder.
  1006.    REM NOTE: Originally i had to manually do this first [call :CleanSteamLibrary "%SteamPath%"],
  1007.    REM       but now Steam smartly lists "C:\Program Files (x86)\Steam" as library 0 in libraryfolders.vdf (even if you never created an additional library folder).
  1008.    REM SOURCE: https://github.com/Cr4zyy/FactorioServerTool/issues/1#issue-233513424
  1009.     for /f usebackq^ delims^=^"^ tokens^=2^,4 %%i in ("%SteamPath%\steamapps\libraryfolders.vdf") do (
  1010.         call :CleanSteamLibrary "%%j"
  1011.     )
  1012.  
  1013.     REM ----- Repair Steam -----
  1014.  
  1015.     if /i "%RUN_STEAM_REPAIR_TOOL%" equ "1" (
  1016.         if exist "%SteamPath%\bin\steamservice.exe" (
  1017.             start "Steam" /wait "%SteamPath%\bin\steamservice.exe" /repair
  1018.         )
  1019.     )
  1020.  
  1021.     REM ----- Restart Steam -----
  1022.  
  1023.     if %NOPAUSE% equ 0 (
  1024.         if exist "%SteamPath%\Steam.exe" (
  1025.             start "Steam" "%SteamPath%\Steam.exe"
  1026.         )
  1027.     )
  1028.  
  1029.     endlocal & goto :eof
  1030.  
  1031. :CleanSteamLibrary
  1032.     setlocal
  1033.  
  1034.     REM ~ removes the " ".
  1035.     set LibraryDirectory=%~1
  1036.  
  1037.     REM Change forward slash to back slash.
  1038.     set LibraryDirectory=%LibraryDirectory:/=\%
  1039.  
  1040.     REM Change double back slash to single back slash.
  1041.     set LibraryDirectory=%LibraryDirectory:\\=\%
  1042.  
  1043.     if not exist "%LibraryDirectory%" goto :eof
  1044.  
  1045.     echo.
  1046.     echo Clean Steam Library: %LibraryDirectory%
  1047.  
  1048.     REM Get game-drive letter.
  1049.    REM set GameDriveLetter=%LibraryDirectory:~0,2%
  1050.    REM echo Game-Drive Letter: %GameDriveLetter%
  1051.  
  1052.     REM ----- Steam cleaning -----
  1053.  
  1054.     REM Steam appcache
  1055.    REM WARNING: Deleting this causes "Steamworks Common Redistributables" to download when Steam is started.
  1056.    REM for /d %%D in ("%LibraryDirectory%\appcache\*") do rd /s /q "%%D"
  1057.    REM del /f /s /q /a "%LibraryDirectory%\appcache\*"
  1058.  
  1059.     REM Steam overlayhtmlcache
  1060.     for /d %%D in ("%LibraryDirectory%\config\overlayhtmlcache\*") do rd /s /q "%%D"
  1061.     del /f /s /q /a "%LibraryDirectory%\config\overlayhtmlcache\*"
  1062.  
  1063.     REM Steam dump files
  1064.     for /d %%D in ("%LibraryDirectory%\dumps\*") do rd /s /q "%%D"
  1065.     del /f /s /q /a "%LibraryDirectory%\dumps\*"
  1066.  
  1067.     REM Steam log files
  1068.     del /f /s /q /a "%LibraryDirectory%\logs\*"
  1069.  
  1070.     REM ----- Steam Download Cache cleaning -----
  1071.    REM https://steamcommunity.com/discussions/forum/1/1698293068434253400/
  1072.    REM https://steamcommunity.com/discussions/forum/1/3315110799614461632/
  1073.  
  1074.     REM If you have any steam downloads then you will probably need to start them over because this will delete the download progress.
  1075.    REM for /d %%D in ("%LibraryDirectory%\steamapps\downloading\*") do rd /s /q "%%D"
  1076.    REM del /f /s /q /a "%LibraryDirectory%\steamapps\downloading\*"
  1077.  
  1078.     for /d %%D in ("%LibraryDirectory%\steamapps\temp\*") do rd /s /q "%%D"
  1079.     del /f /s /q /a "%LibraryDirectory%\steamapps\temp\*"
  1080.  
  1081.     for /d %%D in ("%LibraryDirectory%\steamapps\workshop\downloads\*") do rd /s /q "%%D"
  1082.     del /f /s /q /a "%LibraryDirectory%\steamapps\workshop\downloads\*"
  1083.  
  1084.     for /d %%D in ("%LibraryDirectory%\steamapps\workshop\temp\*") do rd /s /q "%%D"
  1085.     del /f /s /q /a "%LibraryDirectory%\steamapps\workshop\temp\*"
  1086.  
  1087.     REM -----------------------------------------
  1088.  
  1089.     REM Delete Steam shader cache.
  1090.     for /d %%D in ("%LibraryDirectory%\steamapps\shadercache\*") do rd /s /q "%%D"
  1091.     del /f /s /q /a "%LibraryDirectory%\steamapps\shadercache\*"
  1092.  
  1093.     REM Delete all .mdmp files in the Steam directories.
  1094.     del /f /s /q /a "%LibraryDirectory%\*.mdmp"
  1095.  
  1096.     REM Delete all .mdmp files on game drive.
  1097.    REM del /f /s /q /a "%GameDriveLetter%\*.mdmp"
  1098.  
  1099.     REM ----- Game cleaning -----
  1100.  
  1101.     REM ----- Aim Lab -----
  1102.  
  1103.     REM ----- Apex Legends -----
  1104.  
  1105.     for /d %%D in ("%LibraryDirectory%\steamapps\common\Apex Legends\Crashpad\db\*") do rd /s /q "%%D"
  1106.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\Apex Legends\Crashpad\db\*"
  1107.  
  1108.     REM ----- ARK -----
  1109.  
  1110.     for /d %%D in ("%LibraryDirectory%\steamapps\common\ARK\ShooterGame\Saved\Logs\*") do rd /s /q "%%D"
  1111.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\ARK\ShooterGame\Saved\Logs\*"
  1112.  
  1113.     REM ----- ARMA 3 -----
  1114.  
  1115.     REM ----- Deep Rock Galactic -----
  1116.  
  1117.     for /d %%D in ("%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Config\CrashReportClient\*") do rd /s /q "%%D"
  1118.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Config\CrashReportClient\*"
  1119.  
  1120.     for /d %%D in ("%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Crashes\*") do rd /s /q "%%D"
  1121.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Crashes\*"
  1122.  
  1123.     for /d %%D in ("%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Logs\*") do rd /s /q "%%D"
  1124.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\Deep Rock Galactic\FSD\Saved\Logs\*"
  1125.  
  1126.     REM ----- Escape from Tarkov -----
  1127.  
  1128.     REM WARNING: Lots of hardcoded custom paths here.
  1129.  
  1130.     REM The launcher has a "Clean Temp Folder" button that deletes this directory.
  1131.     for /d %%D in ("K:\Battlestate Games\BsgLauncher\Temp\*") do rd /s /q "%%D"
  1132.     del /f /s /q /a "K:\Battlestate Games\BsgLauncher\Temp\*"
  1133.  
  1134.     REM I use this custom temp folder path.
  1135.     for /d %%D in ("E:\Tarkov\*") do rd /s /q "%%D"
  1136.     del /f /s /q /a "E:\Tarkov\*"
  1137.  
  1138.     REM The launcher has a "Clean Temp Folder" button that deletes the contents of this directory.
  1139.    REM The issue is this contains the icon cache and the game has to take longer to regenerate these if you delete them, which means more SSD writing.
  1140.    REM for /d %%D in ("%Temp%\Battlestate Games\*") do rd /s /q "%%D"
  1141.    REM del /f /s /q /a "%Temp%\Battlestate Games\*"
  1142.  
  1143.     REM Delete logs.
  1144.     for /d %%D in ("K:\Battlestate Games\Escape from Tarkov\Logs\*") do rd /s /q "%%D"
  1145.     del /f /s /q /a "K:\Battlestate Games\Escape from Tarkov\Logs\*"
  1146.  
  1147.     for /d %%D in ("K:\Battlestate Games\Escape from Tarkov Arena\Logs\*") do rd /s /q "%%D"
  1148.     del /f /s /q /a "K:\Battlestate Games\Escape from Tarkov Arena\Logs\*"
  1149.  
  1150.     REM ----- Natural Selection 2 -----
  1151.  
  1152.     REM ----- PAYDAY 2 -----
  1153.  
  1154.     for /d %%D in ("%LibraryDirectory%\steamapps\common\PAYDAY 2\mods\logs\*") do rd /s /q "%%D"
  1155.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\PAYDAY 2\mods\logs\*"
  1156.  
  1157.     REM mod-update downloads in "%LibraryDirectory%\steamapps\common\PAYDAY 2\mods\downloads\*"
  1158.     del /f /s /q /a "%LibraryDirectory%\steamapps\common\PAYDAY 2\mods\downloads\*.zip"
  1159.  
  1160.     REM ----- PUBG -----
  1161.  
  1162.     REM Disable PUBG loading screen by deleting loading screen videos
  1163.    REM del /f /s /q /a "%LibraryDirectory%\steamapps\common\PUBG\TslGame\Content\Movies\*"
  1164.  
  1165.     REM Disable PUBG_Test loading screen by deleting loading screen videos
  1166.    REM del /f /s /q /a "%LibraryDirectory%\steamapps\common\PUBG_Test\TslGame\Content\Movies\*"
  1167.  
  1168.     REM ----- Rising Storm 2 -----
  1169.  
  1170.     REM ----- SCUM -----
  1171.  
  1172.     REM ----- VRChat -----
  1173.  
  1174.     endlocal & goto :eof
  1175.  
  1176. :CleanSteamUserData
  1177.     setlocal
  1178.  
  1179.     REM ----- Kill Steam -----
  1180.  
  1181.     REM echo Attempting to close steam.exe gently
  1182.    REM taskkill /im steam.exe >nul 2>&1
  1183.    REM timeout /t 32
  1184.  
  1185.     echo Attempting to kill steam.exe if its still alive
  1186.     taskkill /f /im steam.exe >nul 2>&1
  1187.     timeout /t 3
  1188.  
  1189.     REM ----- Steam cleaning -----
  1190.  
  1191.     REM Chromium Embedded Framework
  1192.     for /d %%D in ("%LocalAppData%\CEF\User Data\Crashpad\reports\*") do rd /s /q "%%D"
  1193.     del /f /s /q /a "%LocalAppData%\CEF\User Data\Crashpad\reports\*"
  1194.  
  1195.     REM html5app htmlcache
  1196.     for /d %%D in ("%LocalAppData%\Steam\html5app\htmlcache\*") do rd /s /q "%%D"
  1197.     del /f /s /q /a "%LocalAppData%\Steam\html5app\htmlcache\*"
  1198.  
  1199.     REM Steam htmlcache
  1200.     for /d %%D in ("%LocalAppData%\Steam\htmlcache\*") do rd /s /q "%%D"
  1201.     del /f /s /q /a "%LocalAppData%\Steam\htmlcache\*"
  1202.  
  1203.     REM ----- Game cleaning -----
  1204.  
  1205.     REM ----- Aim Lab -----
  1206.  
  1207.     REM Delete crash reports.
  1208.     for /d %%D in ("%UserProfile%\AppData\locallow\Statespace\aimlab_tb\backtrace\*") do rd /s /q "%%D"
  1209.     del /f /s /q /a "%UserProfile%\AppData\locallow\Statespace\aimlab_tb\backtrace\*"
  1210.  
  1211.     REM ----- Aliens Colonial Marines -----
  1212.  
  1213.     REM Delete Aliens Colonial Marines crashes.
  1214.     for /d %%D in ("%LocalAppData%\Endeavor\Saved\Config\CrashReportClient\*") do rd /s /q "%%D"
  1215.     del /f /s /q /a "%LocalAppData%\Endeavor\Saved\Config\CrashReportClient\*"
  1216.  
  1217.     REM ----- Apex Legends -----
  1218.  
  1219.     for /d %%D in ("D:\Users\Wolf\Saved Games\Respawn\Apex\assets\*") do rd /s /q "%%D"
  1220.     del /f /s /q /a "D:\Users\Wolf\Saved Games\Respawn\Apex\assets\*"
  1221.  
  1222.     REM ----- ARK -----
  1223.  
  1224.     REM ----- ARMA 3 -----
  1225.  
  1226.     REM Delete all .rpt, .bidmp, and .mdmp files in "%LocalAppData%\Arma 3\" and subdirectories
  1227.     del /f /s /q /a "%LocalAppData%\Arma 3\*.rpt"
  1228.     del /f /s /q /a "%LocalAppData%\Arma 3\*.bidmp"
  1229.     del /f /s /q /a "%LocalAppData%\Arma 3\*.mdmp"
  1230.  
  1231.     del /f /s /q /a "%LocalAppData%\Arma 3\AnimDataCache\*"
  1232.     del /f /s /q /a "%LocalAppData%\Arma 3\MonetizedServersCache\*"
  1233.     del /f /s /q /a "%LocalAppData%\Arma 3\MPMissionsCache\*"
  1234.     del /f /s /q /a "%LocalAppData%\Arma 3\OfficialServersCache\*"
  1235.  
  1236.     for /d %%D in ("%LocalAppData%\Arma 3\squads\*") do rd /s /q "%%D"
  1237.     del /f /s /q /a "%LocalAppData%\Arma 3\squads\*"
  1238.  
  1239.     del /f /s /q /a "%LocalAppData%\Arma 3\SteamPreviewCache\*"
  1240.     del /f /s /q /a "%LocalAppData%\Arma 3 Launcher\Logs\*"
  1241.  
  1242.     REM ----- DOOM -----
  1243.  
  1244.     REM Delete all crash files in DOOM subdirectories
  1245.     del /f /s /q /a "D:\Users\Wolf\Saved Games\id Software\DOOM\base\Crash*.html"
  1246.  
  1247.     REM Delete all errorlog files in DOOM subdirectories
  1248.     del /f /s /q /a "D:\Users\Wolf\Saved Games\id Software\DOOM\base\ErrorLog*.txt"
  1249.  
  1250.     REM ----- DOOM Eternal -----
  1251.  
  1252.     REM Delete DOOM Eternal crashes.
  1253.     for /d %%D in ("D:\Users\Wolf\Saved Games\id Software\DOOMEternal\base\crashes\*") do rd /s /q "%%D"
  1254.     del /f /s /q /a "D:\Users\Wolf\Saved Games\id Software\DOOMEternal\base\crashes\*"
  1255.  
  1256.     REM ----- Escape from Tarkov -----
  1257.  
  1258.     REM Delete analytics.
  1259.     for /d %%D in ("%UserProfile%\AppData\locallow\Battlestate Games\*") do rd /s /q "%%D"
  1260.     del /f /s /q /a "%UserProfile%\AppData\locallow\Battlestate Games\*"
  1261.  
  1262.     REM Delete logs.
  1263.     for /d %%D in ("%LocalAppData%\Battlestate Games\BsgLauncher\Logs\*") do rd /s /q "%%D"
  1264.     del /f /s /q /a "%LocalAppData%\Battlestate Games\BsgLauncher\Logs\*"
  1265.  
  1266.     REM Delete launcher CEF cache.
  1267.     for /d %%D in ("%LocalAppData%\Battlestate Games\BsgLauncher\CefCache\*") do rd /s /q "%%D"
  1268.     del /f /s /q /a "%LocalAppData%\Battlestate Games\BsgLauncher\CefCache\*"
  1269.  
  1270.     REM ----- Natural Selection 2 -----
  1271.  
  1272.     for /d %%D in ("%AppData%\Natural Selection 2\cache\*") do rd /s /q "%%D"
  1273.     del /f /s /q /a "%AppData%\Natural Selection 2\cache\*"
  1274.  
  1275.     for /d %%D in ("%AppData%\Natural Selection 2\dumps\*") do rd /s /q "%%D"
  1276.     del /f /s /q /a "%AppData%\Natural Selection 2\dumps\*"
  1277.  
  1278.     for /d %%D in ("%AppData%\Natural Selection 2\Workshop\*") do rd /s /q "%%D"
  1279.     del /f /s /q /a "%AppData%\Natural Selection 2\Workshop\*"
  1280.  
  1281.     REM ----- PAYDAY 2 -----
  1282.  
  1283.     REM Crash logs.
  1284.     del /f /s /q /a "%LocalAppData%\PAYDAY 2\crash.txt"
  1285.     del /f /s /q /a "%LocalAppData%\PAYDAY 2\crashlog.txt"
  1286.  
  1287.     REM ----- PUBG -----
  1288.  
  1289.     rd /s /q "%LocalAppData%\TslGame\Saved\Config\CrashReportClient\"
  1290.     rd /s /q "%LocalAppData%\TslGame\Saved\Crashes\"
  1291.     rd /s /q "%LocalAppData%\TslGame\Saved\Demos\"
  1292.     rd /s /q "%LocalAppData%\TslGame\Saved\ImGui\"
  1293.     rd /s /q "%LocalAppData%\TslGame\Saved\Logs\"
  1294.     rd /s /q "%LocalAppData%\TslGame\Saved\webcache\"
  1295.  
  1296.     REM ----- Rising Storm 2 -----
  1297.  
  1298.     del /f /s /q /a "%Documents%\My Games\Rising Storm 2\ROGame\Logs\*"
  1299.  
  1300.     REM ----- SCUM -----
  1301.  
  1302.     rd /s /q "%LocalAppData%\SCUM\Saved\Config\CrashReportClient\"
  1303.     rd /s /q "%LocalAppData%\SCUM\Saved\Crashes\"
  1304.     rd /s /q "%LocalAppData%\SCUM\Saved\Logs\"
  1305.  
  1306.     REM ----- Squad -----
  1307.  
  1308.     rd /s /q "%LocalAppData%\SquadGame\Saved\Config\CrashReportClient\"
  1309.     rd /s /q "%LocalAppData%\SquadGame\Saved\Crashes\"
  1310.     rd /s /q "%LocalAppData%\SquadGame\Saved\LicensedServerCache\"
  1311.     rd /s /q "%LocalAppData%\SquadGame\Saved\Logs\"
  1312.  
  1313.     REM Apparently the map icon scale, and other settings?, are saved to the %LocalAppData%\SquadGame\Saved\SaveGames\SquadUI.sav file.
  1314.    REM rd /s /q "%LocalAppData%\SquadGame\Saved\SaveGames\"
  1315.  
  1316.     REM ----- VRChat -----
  1317.  
  1318.     for /d %%D in ("%UserProfile%\AppData\locallow\VRChat\*") do rd /s /q "%%D"
  1319.     del /f /s /q /a "%UserProfile%\AppData\locallow\VRChat\*"
  1320.  
  1321.     endlocal & goto :eof
  1322.  
  1323. REM TODO: Move whatever is useful to :CleanEAapp.
  1324. REM
  1325. REM  :CleanOrigin
  1326. REM      setlocal
  1327. REM
  1328. REM      REM ----- Kill Origin -----
  1329. REM
  1330. REM      REM echo Attempting to close Origin.exe gently
  1331. REM      REM taskkill /im Origin.exe >nul 2>&1
  1332. REM      REM timeout /t 32
  1333. REM
  1334. REM      echo Attempting to kill Origin.exe if its still alive
  1335. REM      taskkill /f /im Origin.exe >nul 2>&1
  1336. REM      timeout /t 3
  1337. REM
  1338. REM      REM ----- Origin cleaning -----
  1339. REM
  1340. REM      cd /d %ProgramData%
  1341. REM      if !errorlevel! equ 0 (
  1342. REM          REM Delete all the files and folders inside \Origin except for "LocalContent" because we're not supposed to for some reason: https://help.ea.com/en-us/help/faq/clear-cache-to-fix-problems-with-your-games/
  1343. REM          for /f "delims=" %%i in ('dir Origin /a /b') do (
  1344. REM              if /i "%%i" NEQ "LocalContent" (
  1345. REM                  REM Delete %%i if its a folder.
  1346. REM                  if exist "Origin\%%i\" (
  1347. REM                      rd /s /q "Origin\%%i\"
  1348. REM                  )
  1349. REM                  REM Delete %%i if its a file.
  1350. REM                  if exist "Origin\%%i" (
  1351. REM                      del /f /s /q /a "Origin\%%i"
  1352. REM                  )
  1353. REM              )
  1354. REM          )
  1355. REM      )
  1356. REM
  1357. REM      REM ----- Determine Origin directory -----
  1358. REM
  1359. REM      REM TODO
  1360. REM
  1361. REM      REM ----- Repair Origin -----
  1362. REM
  1363. REM      REM TODO
  1364. REM
  1365. REM      REM ----- Restart Origin -----
  1366. REM
  1367. REM      if %NOPAUSE% equ 0 (
  1368. REM          REM if exist "%SteamPath%\Steam.exe" (
  1369. REM          REM     start "Steam" "%SteamPath%\Steam.exe"
  1370. REM          REM )
  1371. REM
  1372. REM          if exist "G:\Origin\Origin.exe" (
  1373. REM              start "Origin" "G:\Origin\Origin.exe"
  1374. REM          )
  1375. REM      )
  1376. REM
  1377. REM      endlocal & goto :eof
  1378. REM
  1379. REM  :CleanOriginUserData
  1380. REM      setlocal
  1381. REM      REM SOURCE: https://help.ea.com/en-us/help/faq/clear-cache-to-fix-problems-with-your-games/
  1382. REM
  1383. REM      REM ----- Kill Origin -----
  1384. REM
  1385. REM      REM echo Attempting to close Origin.exe gently
  1386. REM      REM taskkill /im Origin.exe >nul 2>&1
  1387. REM      REM timeout /t 32
  1388. REM
  1389. REM      echo Attempting to kill Origin.exe if its still alive
  1390. REM      taskkill /f /im Origin.exe >nul 2>&1
  1391. REM      timeout /t 3
  1392. REM
  1393. REM      REM ----- Origin cleaning -----
  1394. REM
  1395. REM      rd /s /q "%AppData%\Origin\"
  1396. REM      rd /s /q "%LocalAppData%\Origin\"
  1397. REM
  1398. REM      endlocal & goto :eof
  1399.  
  1400. :CleanEAapp
  1401.     setlocal
  1402.  
  1403.     REM Remove old EA app clients.
  1404.     rd /s /q "%ProgramFiles%\Electronic Arts\EA Desktop\outdatedEADesktop\"
  1405.     rd /s /q "%ProgramFiles%\Electronic Arts\EA Desktop\StagedEADesktop\"
  1406.  
  1407.     endlocal & goto :eof
  1408.  
  1409. :CleanCODWarzoneUserData
  1410.     setlocal
  1411.  
  1412.     REM Delete files named like this: "crashdump_132287692447320985.zip".
  1413.     del /f /s /q /a "%Documents%\Call of Duty Modern Warfare\archive\*"
  1414.  
  1415.     REM Delete files named like this: "~crash".
  1416.     del /f /s /q /a "%Documents%\Call of Duty Modern Warfare\report\*"
  1417.  
  1418.     REM Delete files named like this: "gpu_report-2020_08_25-22_38_19.txt".
  1419.     del /f /s /q /a "%Documents%\Call of Duty Modern Warfare\report\gpu\*"
  1420.  
  1421.     REM Delete all Activision crash report folders.
  1422.     for /d %%D in ("%LocalAppData%\Activision\*") do rd /s /q "%%D"
  1423.     del /f /s /q /a "%LocalAppData%\Activision\*"
  1424.  
  1425.     endlocal & goto :eof
  1426.  
  1427. :CleanBattleNet
  1428.     setlocal
  1429.  
  1430.     REM Delete Blizzard Entertainment Battle.net cache.
  1431.     for /d %%D in ("%ProgramData%\Blizzard Entertainment\Battle.net\Cache\*") do rd /s /q "%%D"
  1432.     del /f /s /q /a "%ProgramData%\Blizzard Entertainment\Battle.net\Cache\*"
  1433.  
  1434.     REM Delete Battle.net caches.
  1435.     for /d %%D in ("%ProgramData%\Battle.net\Agent\data\cache\*") do rd /s /q "%%D"
  1436.     del /f /s /q /a "%ProgramData%\Battle.net\Agent\data\cache\*"
  1437.  
  1438.     for /d %%D in ("%LocalAppData%\Battle.net\BrowserCache\*") do rd /s /q "%%D"
  1439.     del /f /s /q /a "%LocalAppData%\Battle.net\BrowserCache\*"
  1440.  
  1441.     for /d %%D in ("%LocalAppData%\Battle.net\Cache\*") do rd /s /q "%%D"
  1442.     del /f /s /q /a "%LocalAppData%\Battle.net\Cache\*"
  1443.  
  1444.     REM Delete all .log files in Battle.net subdirectories.
  1445.     del /f /s /q /a "%ProgramData%\Battle.net\*.log"
  1446.     del /f /s /q /a "%LocalAppData%\Battle.net\*.log"
  1447.  
  1448.     REM Remove old Battle.net clients.
  1449.     set directory=G:\Battle.net\Battle.net
  1450.     set pathname="%directory%\Battle.net.*"
  1451.     set LatestVersionPath=""
  1452.     for /f %%d in ('dir %pathname% /b /a:d /o:d') do set LatestVersionPath="%directory%\%%d"
  1453.     if /i not %LatestVersionPath%=="" (
  1454.        REM  echo Latest version detected: %LatestVersionPath%
  1455.         for /f %%d in ('dir %pathname% /b /a:d /o:d') do (
  1456.             if /i not "%directory%\%%d"==%LatestVersionPath% (
  1457.                 echo Removing old version: "%directory%\%%d"
  1458.                 rd /s /q "%directory%\%%d"
  1459.             )
  1460.         )
  1461.     )
  1462.  
  1463.     REM Remove old Battle.net agents.
  1464.     set directory=%ProgramData%\Battle.net\Agent
  1465.     set pathname="%directory%\Agent.*"
  1466.     set LatestVersionPath=""
  1467.     for /f %%d in ('dir %pathname% /b /a:d /o:d') do set LatestVersionPath="%directory%\%%d"
  1468.     if /i not %LatestVersionPath%=="" (
  1469.        REM  echo Latest version detected: %LatestVersionPath%
  1470.         for /f %%d in ('dir %pathname% /b /a:d /o:d') do (
  1471.             if /i not "%directory%\%%d"==%LatestVersionPath% (
  1472.                 echo Removing old version: "%directory%\%%d"
  1473.                 rd /s /q "%directory%\%%d"
  1474.             )
  1475.         )
  1476.     )
  1477.  
  1478.     endlocal & goto :eof
  1479.  
  1480. :CleanBattlefield2042UserData
  1481.     setlocal
  1482.  
  1483.     REM Delete folders containing shader files named like this: "7040.md_veh_car__hdt_storm_01ob_veh_car__hdt_storm_04_base_bundle_3p\shaderdb.PcDx12". Supposedly this helps with performance but i question this?
  1484.     for /d %%D in ("%Documents%\Battlefield 2042\cache\*") do rd /s /q "%%D"
  1485.     del /f /s /q /a "%Documents%\Battlefield 2042\cache\*"
  1486.  
  1487.     REM Delete crash dumps.
  1488.     for /d %%D in ("%Documents%\Battlefield 2042\CrashDumps\*") do rd /s /q "%%D"
  1489.     del /f /s /q /a "%Documents%\Battlefield 2042\CrashDumps\*"
  1490.  
  1491.     endlocal & goto :eof
  1492.  
  1493. :CleanUbisoft
  1494.     setlocal
  1495.  
  1496.     REM Delete crash dumps.
  1497.     for /d %%D in ("G:\Ubisoft\Ubisoft Game Launcher\crashes\*") do rd /s /q "%%D"
  1498.     del /f /s /q /a "G:\Ubisoft\Ubisoft Game Launcher\crashes\*"
  1499.  
  1500.     endlocal & goto :eof
  1501.  
  1502. :CleanEpicGamesLauncher
  1503.     setlocal
  1504.  
  1505.     REM Remove web caches.
  1506.     set directory=%LocalAppData%\EpicGamesLauncher\Saved
  1507.     set pathname="%directory%\webcache_*"
  1508.     for /f %%d in ('dir %pathname% /b /a:d /o:d') do (
  1509.         echo Removing web caches: "%directory%\%%d"
  1510.         rd /s /q "%directory%\%%d"
  1511.     )
  1512.  
  1513.     endlocal & goto :eof
  1514.  
  1515. :Clean7Zip
  1516.     setlocal
  1517.  
  1518.     REM Remove tracks. 7-Zip tracks every archive you ever open with it in View > Folder History.
  1519.     reg delete "HKCU\SOFTWARE\7-Zip\FM" /v "FolderHistory" /f
  1520.     reg delete "HKCU\SOFTWARE\7-Zip\FM" /v "FolderShortcuts" /f
  1521.     reg delete "HKCU\SOFTWARE\7-Zip\FM" /v "PanelPath0" /f
  1522.     reg delete "HKCU\SOFTWARE\7-Zip\FM" /v "PanelPath1" /f
  1523.  
  1524.     endlocal & goto :eof
  1525.  
  1526. :CleanUser
  1527.     setlocal
  1528.  
  1529.     call :CleanAdobe
  1530.     call :CleanOkular
  1531.     call :CleanOneNote
  1532.     call :CleanMirc
  1533.     call :CleanAtom
  1534.     call :CleanDiscord
  1535.     call :CleanVirtualBox
  1536.     call :CleanVMware
  1537.     call :CleanJetBrainsDotPeek
  1538.     call :CleanVisualStudio
  1539.     call :CleanVSCode
  1540.     call :CleanNuGetCache
  1541.     call :CleanSmartGit
  1542.     call :CleanWindowsUserData
  1543.     call :CleanFirefox
  1544.     call :CleanWaterfox
  1545.     call :CleanLibreWolf
  1546.     call :CleanEdge
  1547.     call :CleanGoogle
  1548.     call :CleanOBS
  1549.     call :CleanVLC
  1550.     call :CleanLibreOffice
  1551.     call :CleanSteamUserData
  1552.    REM call :CleanOriginUserData
  1553.     call :CleanCODWarzoneUserData
  1554.     call :CleanBattleNet
  1555.     call :CleanBattlefield2042UserData
  1556.     call :Clean7Zip
  1557.  
  1558.     endlocal & goto :eof
  1559.  
  1560. :Work
  1561.     setlocal
  1562.  
  1563.     REM ----- Cleaning user data -----
  1564.  
  1565.     REM Clean the current user's data.
  1566.    REM Determine Document-folder location. The rest of the variables don't need to be modified since they are already pointing at the current user.
  1567.     for /f "tokens=1,3" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal') do set Documents=%%j
  1568.     if exist %Documents% (
  1569.         call :CleanUser
  1570.     )
  1571.  
  1572.     REM Clean "Stream" user data.
  1573.     if exist %UserProfile%\..\Stream (
  1574.         set Documents=D:\Users\Stream\Documents
  1575.         set AppData=%UserProfile%\..\Stream\AppData\Roaming
  1576.         set LocalAppData=%UserProfile%\..\Stream\AppData\Local
  1577.         set UserProfile=%UserProfile%\..\Stream
  1578.         call :CleanUser
  1579.     )
  1580.  
  1581.     REM If you have other user's you want to clean you can add them here like i did for the "Stream" user.
  1582.  
  1583.     REM TODO: Find an automatic way to clean all users.
  1584.  
  1585.     REM ----- Non-user-data cleaning -----
  1586.  
  1587.     REM These do not need to be repeated for each user.
  1588.     call :CleanUnixFiles
  1589.     call :CleanChkdskFiles
  1590.     call :CleanWindows
  1591.     call :CleanNVIDIA
  1592.     call :CleanDropbox
  1593.     call :CleanSteam
  1594.    REM call :CleanOrigin
  1595.     call :CleanUbisoft
  1596.     call :CleanEpicGamesLauncher
  1597.     call :CleanEAapp
  1598.  
  1599.     REM -----
  1600.  
  1601.     REM TODO: C:\Users\Wolf\MicrosoftEdgeBackups
  1602.    REM this might be something we can delete.
  1603.    REM People say closing edge deletes it but i didn't see that effect.
  1604.    REM Also ppl say its just a backup of your settings idk, https://www.tenforums.com/browsers-email/117960-no-more-microsoftedgebackups.html
  1605.  
  1606.     REM TODO: I think some of the attrib -r -s -h calls are unnecessary.
  1607.  
  1608.     endlocal
  1609.  
  1610. :End
  1611.     if %NOPAUSE% equ 0 pause
  1612.     goto :eof
Add Comment
Please, Sign In to add comment