Forum Discussion

ConstanceBrody's avatar
ConstanceBrody
Copper Contributor
Dec 20, 2024

Need current Win11 cleanup batch script and other

I'm looking for assistance in creating a batch script for Windows 11 that effectively cleans up unnecessary files and optimizes system performance. 

 

6 Replies

  • MaineLobster's avatar
    MaineLobster
    Iron Contributor

    This script will irreversibly delete files. Be sure you want to delete these files primarily in the Temporary and Prefetch directories.You must run this script as an administrator to clean system files and directories. Consider backing up important data before running scripts like this, especially if you are unsure about any specific directories.

  • Barbarank's avatar
    Barbarank
    Iron Contributor
    @echo off
    title Windows 11 Cleanup Script
    echo Cleaning up unnecessary files...
    
    :: Delete temporary files
    del /q /f "%temp%\*"
    echo Deleted files in %temp%
    
    :: Clean the Windows Temp folder
    del /q /f "C:\Windows\Temp\*"
    echo Deleted files in C:\Windows\Temp
    
    :: Clear the Recycle Bin
    echo Clearing Recycle Bin...
    PowerShell.exe -NoProfile -Command "Clear-RecycleBin -Confirm:$false"
    echo Recycle Bin cleared.
    
    :: Clean Windows Update cache (optional)
    echo Cleaning Windows Update cache...
    net stop wuauserv
    del /q /f "C:\Windows\SoftwareDistribution\Download\*"
    net start wuauserv
    echo Windows Update cache cleaned.
    
    :: Run Disk Cleanup (optional additional cleanup method)
    echo Running Disk Cleanup...
    cleanmgr /sagerun:1
    
    :: Defragmenting Disk drives (optional)
    echo Defragmenting all drives...
    defrag C: -w
    echo Disk defragmentation completed.
    
    echo Cleanup complete. Please restart your system if required.
    pause

     

  • Timothy310's avatar
    Timothy310
    Iron Contributor

    One of the biggest rookie mistakes is trying to run a script that needs elevated permissions without actually running it as an administrator. Tasks like deleting system files or clearing the Windows Update cache require admin access. 

    Solution: Always right-click your batch file and choose "Run as administrator." You can even set it to always run as an admin by going to the file properties and adjusting the settings under the Compatibility tab.

  • Hannaness's avatar
    Hannaness
    Iron Contributor

    Creating a batch script for cleaning up unnecessary files on Windows 11 can help improve system performance by deleting temporary files, clearing cache, and removing other unwanted data.

Resources