The script is useful, but there are some differences between Windows 10, 11, 12 and MS Server when deleting temporary files and the Recycle Bin:
IN ADVANCE:
1. Include system-wide temp folder: `%temp%` only deletes user-specific files. The system-wide temp folder (`C:\Windows\Temp`) could also be included.
2. Empty the recycle bin for all users: Instead of `rd /s /q C:\$Recycle.Bin`, it is better to use `PowerShell` to empty the recycle bin for all users.
3. Check admin rights: Some commands require elevated rights. A query or direct elevation can be helpful.
@echo off
:: Checks if the script is running as administrator
net session >nul 2>& 1 || ( echo Please run as administrator! & pause & exit )
echo Deleting temporary files ...
del /s /q "%temp% \*.* " >nul 2>&1
rd /s /q "%temp%" >nul 2>&1
md "%temp%" >nul 2>& 1
echo Deleting system-wide temporary files ...
del /s /q "C: \ Windows \ Temp \*.* " >nul 2>&1
rd /s /q "C: \ Windows \ Temp" >nul 2>&1
md "C: \ Windows \ Temp" >nul 2>&1
echo Empty the Recycle Bin ...
PowerShell -Command "Clear-RecycleBin -Force"
echo Cleanup completed!
pause
This version:
- Checks admin rights
- Also deletes system-wide temp files
- Empty the recycle bin with PowerShell
2.) Differences between Windows 10, 11, 12 and MS Server
when deleting temporary files and the recycle bin:
1. Temporary files (%temp% & C:\Windows\Temp)
✅ Windows 10, 11, 12 & Server
- `%temp%` is unique to each user.
- `C:\Windows\Temp` is used by system processes and requires administrator rights to delete.
- In Windows Server, some files in `C:\Windows\Temp` may be used by running services, so not all of them can be deleted.
2. Recycle Bin (`C:\$Recycle.Bin`)
🔹 Windows 10, 11, 12:
- `C:\$Recycle.Bin` contains all users' recycle bins.
- In newer versions of Windows, `Clear-RecycleBin` via PowerShell is more reliable.
🔹 Windows Server:
- Server administrators often disable the recycle bin, so emptying it may not be necessary.
- The command `PowerShell -Command "Clear-RecycleBin -Force"` works in Windows Server 2012 R2 and later.
3. Differences in the cleanup
💡 Windows 11 & 12:
- Use "Storage Sense", which automatically deletes temp files.
- Some temp files are locked by the system and cannot be removed with `del`.
💡 Windows Server:
- `C:\Windows\Temp` may contain sensitive logs or temporary installation files that may not be deleted.
- Some cleanup tools (like `Disk Cleanup`) are not installed by default on servers.
Recommended customization for Windows Server
If the script is running on Windows Server , it would be better to just delete `%temp%` first and not empty the Recycle Bin automatically. Instead, you could ask for confirmation:
@echo off
net session >nul 2>& 1 || ( echo Please run as administrator! & pause & exit )
echo Delete user temp files ...
del /s /q "%temp% \*.* " >nul 2>&1
rd /s /q "%temp%" >nul 2>&1
md "%temp%" >nul 2>& 1
echo Deleting system-wide temp files ...
del /s /q "C: \ Windows \ Temp \*.* " >nul 2>&1
rd /s /q "C: \ Windows \ Temp" >nul 2>&1
md "C: \ Windows \ Temp" >nul 2>&1
:: Ask for trash cleanup on server version
ver | findstr /i "server" >nul
if %errorlevel% equ 0 (
echo Do you want to empty the recycle bin ? ( Y/N )
set /p choice =
if /I "%choice%" == "Y" PowerShell -Command "Clear-RecycleBin -Force") else (
echo Empty the recycle bin ...
PowerShell -Command "Clear-RecycleBin -Force")
echo Cleanup completed!
pause
To clear the icon cache and thumbnail cache in Windows 10, 11 and 12, you can use the following batch script: 1. Clear icon and thumbnail cache in Windows?
Windows batch scripts, correctly called batch files, are simple text files that contain a series of commands that can be executed in the command line environment
To create a simple FTP connection using a Windows 12, 11, or 10 batch file and run some basic FTP commands, you can create a batch file Which executes the
To clear the icon cache and thumbnail cache in Windows 10, 11 and 12, you can use the following batch script: 1. Clear icon and thumbnail cache in Windows?
The script is useful, but there are some differences between Windows 10, 11, 12 and MS Server when deleting temporary files and the Recycle Bin: IN ADVANCE:
This website does not store personal data. However, third-party providers are used to display ads, which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF). The CMP ID is 300 and can be individually customized at the bottom of the page. more Infos & Privacy Policy ....