Last Update: Sep 04, 2024 | Published: Feb 12, 2016
In a previous article, I explained how to use the Disk Cleanup utility to clean up temporary files on your Windows 10 machine. If you’re an administrator of a network that contains multiple computers, then running manual configuration tasks can be very time consuming. In this article, I’ll show you how to automate this process for larger environments.
If you want to pre-configure these options on a remote computer and offer the user the ability to execute a script that will clean their disk, then you can use the following instructions to create .BAT file, place it on the computer’s desktop or anywhere you like, and execute it with elevated permissions:
@ECHO OFF REM Enable components to cleanup REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesActive Setup Temp Folders" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesBranchCache" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesDownloaded Program Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesGameNewsFiles" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesGameStatisticsFiles" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesGameUpdateFiles" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesInternet Cache Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesMemory Dump Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesOffline Pages Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesOld ChkDsk Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesPrevious Installations" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesRecycle Bin" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesService Pack Cleanup" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesSetup Log Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesSystem error memory dump files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesSystem error minidump files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesTemporary Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesTemporary Setup Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesTemporary Sync Files" /V StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesThumbnail Cache" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesUpdate Cleanup" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesUpgrade Discarded Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesUser file versions" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Defender" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Error Reporting Archive Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Error Reporting Queue Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Error Reporting System Archive Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Error Reporting System Queue Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows ESD installation files" /v StateFlags0100 /d 2 /t REG_DWORD /f REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesWindows Upgrade Log Files" /v StateFlags0100 /d 2 /t REG_DWORD /f REM Run cleanup IF EXIST %SystemRoot%SYSTEM32cleanmgr.exe START /WAIT cleanmgr /sagerun:100
If you would like to schedule Disk Cleanup to run automatically, then you can do so using the Task Scheduler. Assuming you’ve pre-configured the system with the required settings to be cleaned by using the cleanmgr /sageset:100 command, or running the registry settings that are provided in this article, then the system will already know that if it runs cleanmgr /sagerun:100, and all the required files will be cleaned.
Now we need to create the scheduled task to run the command.
To do so, follow these steps:
1. Open Task Scheduler from the Administrative Tools folder.
2. In the Task Scheduler window, click on “Create Basic Task.”
3. Give the task a name and description. Click “Next.”
4. Select the option that best suits your needs. For this article, we’ll be using the monthly option. Click “Next.”
5. Select when you’d like to run the task. I chose the first Sunday of each month. Click “Next.”
6. Now we need to give our task an action to execute. In this article, we’ll select “Start a program.” Click “Next.”
7. Use the following path:
C:Windowssystem32cleanmgr.exe
Add argument as
/sagerun:100
Click “Next.”
8. To complete the creation of our task, click “Finish.”
Now, either wait for the time of the task to arrive, or, if you want to check if it works right now, find it in the scheduled tasks library, right-click it, and select “Run.” If it runs, you’ll see it, and you can also check the last run status.