FocusedWolf

Windows 10+11; Cleanup.bat

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