FocusedWolf

Windows 10: Cleanup.bat

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