Step-by-step guide to building an advanced Windows cleaning tool — without third-party applications. -Upgraded version
Introduction
Over time, Windows accumulates a lot of junk files that take up space on your hard drive and can slow down your computer. Instead of downloading a specialized program, you can create your own advanced cleaning tool using a simple batch file that you can run with a single click. I will show you how to clean the most important parts of your system safely and without complicated steps. In the previous article I presented a simple program in code to clean your computer, today I take it a step further and present you its updated version, with much more cleaning capabilities.
💡 What you will learn: How to create an advanced cleaning tool that will delete temporary files, prefetch files, recycle bin, browser cache (without touching passwords!), Windows Update cache, thumbnail cache, log files and much more with one click.
What Files Can I Clean?
Temporary Files (Temp)\
When you work on your computer or use the internet, Windows stores temporary files in special folders. These files are normally deleted automatically, but sometimes they remain and take up valuable space.
Prefetch files
Prefetch is a system that stores information about how programs start up, so they load faster. However, some of these files may be from old programs that you no longer use.
Recycle Bin
The Recycle Bin stores your deleted files, but even after you empty it, some temporary data may remain. By cleaning it properly, you can free up additional space.
Windows Update Cache
Every time Windows is updated, update files are stored on the system. After a successful installation, these files are no longer needed and can be deleted to free up many gigabytes of space.
Browser Cache
Web browsers (Chrome, Edge, Firefox) store images, scripts, and other page data to make pages load faster. Over time, these cache files can take up a lot of space. Important: The tool ONLY clears cache and NOT passwords, cookies, or history!
Thumbnail Cache
The image thumbnails you see in folders are stored in special cache files. If these become corrupted or accumulate, they can cause problems or take up space unnecessarily.
Windows Error Reports & Log Files
Every time a program crashes, Windows creates error reports and log files. These accumulate and are rarely needed after they are sent to Microsoft.
Memory Dumps
When the system encounters a serious error (Blue Screen), it creates memory dump files that can be very large. If you don't need them for debugging, you can delete them.
Delivery Optimization Files
Windows uses peer-to-peer technology to share updates with other computers. These cache files can be safely deleted after the updates are complete.
⚠️ Important: Before you start, create a System Restore Point. If something goes wrong, you can go back to the previous point. Go to: Settings → System → About → System Protection.
Step 1: Create the Advanced Cleanup File
We'll create an advanced batch file — a file of commands that your computer will automatically execute and clean up 15 different file categories. Follow these steps:
Open Notepad.
Copy and paste the code below
Advanced Windows Cleanup Tool (BAT)
@echo off REM Advanced Windows Cleanup Tool REM Enhanced BAT file to delete unnecessary files and cache title ADVANCED WINDOWS CLEANUP TOOL color 0A REM Check for admin rights net session >nul 2>&1 if %errorLevel% neq 0 ( echo. echo =========================================== echo ADMINISTRATOR RIGHTS REQUIRED echo ==================================== echo. pause exit ) echo. echo ==================================== echo ADVANCED WINDOWS CLEANUP TOOL echo =========================================== echo. echo This program will clean: echo - Temporary files (User & System) echo - Prefetch files echo - Recycle Bin echo - Windows Update Cache echo - Browser Caches (passwords safe!) echo - Thumbnail Cache echo - Windows Error Reports echo. pause REM Clean user Temp folder echo. echo [1/15] Cleaning user temporary files... cd /d %temp% for /d %%x in (*) do @rd /s /q "%%x" 2>nul del /q *.* 2>nul echo Done! REM Clean Windows Temp echo. echo [2/15] Cleaning system temporary files... cd /d C:\Windows\Temp for /d %%x in (*) do @rd /s /q "%%x" 2>nul del /q *.* 2>nul echo Done! REM Clean Prefetch echo. echo [3/15] Cleaning Prefetch files... cd /d C:\Windows\Prefetch del /q *.* 2>nul echo Done! REM Clean Recycle Bin echo. echo [4/15] Cleaning Recycle Bin... rd /s /q %systemdrive%\$Recycle.bin 2>nul md %systemdrive%\$Recycle.bin 2>nul echo Done! REM Clean Windows Update Cache echo. echo [5/15] Cleaning Windows Update cache... net stop wuauserv >nul 2>&1 rd /s /q C:\Windows\SoftwareDistribution\Download 2>nul md C:\Windows\SoftwareDistribution\Download 2>nul net start wuauserv >nul 2>&1 echo Done! REM Clean Delivery Optimization echo. echo [6/15] Cleaning Delivery Optimization files... net stop dosvc >nul 2>&1 del /f /s /q C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\Windows\DeliveryOptimization\Cache\*.* 2>nul net start dosvc >nul 2>&1 echo Done! REM Clean Thumbnail Cache echo. echo [7/15] Cleaning Thumbnail cache... taskkill /f /im explorer.exe >nul 2>&1 del /f /s /q /a %LocalAppData%\Microsoft\Windows\Explorer\thumbcache_*.db 2>nul start explorer.exe echo Done! REM Clean Windows Error Reports echo. echo [8/15] Cleaning Windows Error Reports... del /f /s /q C:\ProgramData\Microsoft\Windows\WER\ReportQueue\*.* 2>nul echo Done! REM Clean Chrome Cache echo. echo [11/15] Cleaning Chrome cache (passwords safe)... taskkill /f /im chrome.exe >nul 2>&1 del /f /s /q "%LocalAppData%\Google\Chrome\User Data\Default\Cache\*.*" 2>nul echo Done! REM Clean DNS Cache echo. echo [14/15] Flushing DNS cache... ipconfig /flushdns >nul 2>&1 echo Done! REM Completion echo. echo ==================================== echo CLEANUP COMPLETED! echo ==================================== echo. echo Your computer should run faster now! echo Consider restarting your PC for best results. echo. pause exit
⚠️ Important: Run this script as Administrator! Right-click and select "Run as administrator". If you do not have administrator rights, an error message will appear.
✅ Code copied!
Click File → Save As
In "Save as type" select "All Files (*.*)"
Name the file: advanced_cleanup.bat
Save it in an easy place (e.g. Desktop)
Step 2: Run the File
Now that you have created the file, it is very important to execute it correctly:
Right-click on the advanced_cleanup.bat file
Select "Run as administrator" - REQUIRED!
If you don't run it as administrator, the script will notify you and stop.
Press Enter when prompted.
Wait until the cleaning is finished (it may take 5-10 minutes)
💡 Advice: The program will notify you of each step it takes. You'll see messages saying "Cleaning..." and "Done!" for each task. Don't worry if some steps take longer - that's normal!
⚠️ Important Note for Browsers: During the cleaning process, browsers (Chrome, Edge, Firefox) will be automatically closed to delete cache files. YOUR CODES WILL REMAIN SAFE! The script only deletes cache, not passwords, cookies or history.
What Exactly Does the Advanced Archive Do?
The advanced_cleanup.bat file performs 15 main tasks in a specific order:
1: Deletes the user's temporary files (%temp% folder)
2: Deletes temporary Windows files (C:\Windows\Temp)
3: Deletes Prefetch files (C:\Windows\Prefetch)
4: Empty the recycle bin thoroughly
5: Clears Windows Update cache (can free up many GB!)
6: Deletes Delivery Optimization files
7: Clears the Thumbnail cache (image thumbnails)
8: Deletes Windows Error Reports
9: Cleans system log files
10: Deletes memory dump files (from crashes)
11: Clears Chrome cache (passwords safe!)
12: Clears Edge cache (passwords safe!)
13: Clears Firefox cache (passwords safe!)
14: Clears the DNS cache
15: The Windows Disk Cleanup utility is running.
FAQ
Is advanced cleaning safe?
Yes, absolutely! All files that are deleted are temporary or useless. The script does not touch any important system files, programs, or your personal data. Browser passwords, cookies, and history remain intact. Even if something goes wrong, you have the System Restore Point you created.
Why does it need to run as Administrator?
Some folders like Windows Update cache, Error Reports, and system logs require administrator privileges to be deleted. If you don't run it as administrator, the script will detect this and stop immediately, notifying you.
What will I win?
You will free up a significant amount of disk space (usually 5-20 GB, depending on how long you haven't cleaned) and your computer will run noticeably faster. You will see a difference in startup, system responsiveness, and browser speed.
Are my browser passwords safe?
Absolutely safe! The script ONLY deletes cache files (temporary image files, scripts, etc.) and NOT passwords, cookies, history, bookmarks or extensions. All your login data will remain exactly as it was.
Can I do it more often?
Of course! You can run it every week or even every day without any problem. The more often you run it, the less time it will take each time because there won't be many files accumulated.
What if a file is in use?
If the file is in use by the system or a program, the batch file will ignore it and continue with the rest. For this reason, the script closes the browsers before clearing their caches. This is normal and not a problem.
Why do browsers close during cleaning?
Browsers must be closed for the script to delete their cache files. If they are open, the files are locked and cannot be deleted. Once the cleanup is complete, you can open them again normally.
How long will it take?
The first time can take 5-10 minutes, depending on how many files have accumulated. Subsequent times will be much faster, usually 2-3 minutes. The Windows Update cache is usually the most time-consuming part.
Additional Tips
If you want to make it even more automatic, you can schedule the file to run every week using Task Scheduler Windows. Simply search for "Task Scheduler" in the Start menu and create a new task that will run advanced_cleanup.bat at regular intervals with administrator privileges.
For best results, run the script when you're not doing anything important on your computer. It's ideal to do this before you close for the day so you can restart later.
Task Scheduler Optimization
To create an automatic task in Task Scheduler:
- Open Task Scheduler (press Windows + R, type "taskschd.msc")
- Click "Create Basic Task" in the right panel
- Give it a name, e.g. "Weekly Cleanup"
- Select "Weekly" as the trigger
- Choose the day and time you want
- In Action, select "Start a program"
- Find your advanced_cleanup.bat file
- Finally, check "Open Properties" before clicking Finish.
- In Properties, check "Run with highest privileges"
Tips for Maximum Performance
To get the most out of cleaning:
- Restart the computer after cleaning.
- Run the script at least once a month
- If you have an SSD, cleaning it will help extend its lifespan.
- If you're low on storage, run it more often.
- Keep the .bat file in a safe place for future use.
In essence, you have now created your own advanced cleaning tool without downloading any software from the internet. This means more security and complete control over your computer. You know exactly what each line of code does and can customize it to your needs.
⚠️ Last Reminder: Always back up your important files before making any major changes to your system. And remember to create a System Restore Point before running the file for the first time. Also, always run it as Administrator for all its features to work.
What the Script DOES NOT Delete (For Your Safety)
It is important to know what remains safe:
- Browser passwords
- Cookies and session data
- Browsing history
- Bookmarks/Favorites
- Extensions and add-ons
- Saved payment information
- Autofill data (addresses, emails, etc.)
- Personal files (Documents, Pictures, Downloads)
- Installed programs
- System and application settings
Dealing with Problems
The script does not run or stops immediately
If the script opens and closes immediately without doing anything, it means you haven't run it as Administrator. Right-click and select "Run as administrator".
Some step took too long
It is normal for some steps (especially the Windows Update cache and browser caches) to take several minutes if you have never cleaned before. Be patient and do not interrupt the process.
Computer is slow after cleaning
Do a full restart. Sometimes Windows needs to restart to complete the cleanup and free up resources. After the restart you will see the improvement.
"Access Denied" message appears
This means that a file is locked or needs special permissions. The script will bypass it and continue. No problem - it just won't delete that particular file.
I want to see what exactly is being deleted.
You can remove the "2>nul" from the commands to see each file being deleted in detail. Be careful though - it will display a lot of lines and the process will be slower.
Conclusion
Now you have a complete, safe and highly effective cleaning tool that cleans 15 different file categories and can free up many gigabytes of space. You no longer need any third-party programs. Just click, wait a few minutes, and your computer will thank you with significantly better performance!
Most importantly: You have full control and understanding of what is happening on your computer. You know exactly what is being deleted and what is not, and you can customize the script as you wish. That is the true power of technology - when you control it!
💡 Tip: If you want, you can create a shortcut to the file on your desktop and change its icon to something nicer. That way, you'll always have easy access to your cleaning tool!
RELATED TOPICS
Loading comments...