How to Clean Windows and Remove Junk Files With One Script
A tiny script can turn a sluggish computer into a fast machine — and even become a real source of income as a maintenance service.
A six-line script cleans Windows for free — and can even become a paid service:
- Always create a restore point before running maintenance scripts.
- The limpeza.bat script removes only temporary files — documents and passwords are not touched.
- Configure Disk Cleanup once with
cleanmgr /sageset:1so the script knows what to clean. - Automate it with Task Scheduler so it runs by itself every week.
- It can become a paid service: cleaning, optimisation and recurring monthly maintenance.
🧹 Clean Windows With One Script
If your computer is slow, freezing or taking ages to open things, part of the problem is often digital junk: temporary files left behind by installers, updates, browsers and programs that never clean up after themselves. Over months, that can add up to several gigabytes.
In this guide you’ll create a small script that removes that junk in seconds, schedule it to run by itself every week — and, if you want, turn this knowledge into a maintenance service for other people.

⚠️ Create a Restore Point
Before running any maintenance script on Windows, I recommend a professional habit: create a system restore point. It lets you roll back Windows settings if anything unexpected happens.
1. Press Windows + R
2. Type: SystemPropertiesProtection
3. Select the Windows drive (usually C:)
4. Click Create
5. Give it a name such as: Before_Windows_cleanup
6. Wait for it to finishThis habit is what separates an amateur from a professional: any script can, in theory, interact in an unexpected way with a specific setup (custom drivers, group policies, manually changed permissions). The restore point is your free safety net — it takes under two minutes and can save hours of headaches.
🧹 Cleaning in Practice
Here is the script. Open Notepad, paste the code, save it as limpeza.bat (in “Save as type”, choose “All files”) and run it as administrator:
@echo off
echo Cleaning temporary files...
del /s /f /q %temp%\*
del /s /f /q C:\Windows\Temp\*
cleanmgr /sagerun:1
echo Done!
pause
Some files will show “access denied” or “in use” while the script runs. That’s normal: they belong to programs that are open right now, and Windows protects them. The script simply skips them and moves on.
⚙️ Configure the Disk Cleanup Profile Once
The line cleanmgr /sagerun:1 runs Disk Cleanup using a saved profile number 1. But that profile has to exist first — otherwise Disk Cleanup has nothing selected to clean. Create it once:
- Open the Start menu, type cmd, right-click it and choose Run as administrator.
- Type
cleanmgr /sageset:1and press Enter. - In the window that opens, tick what you want cleaned (Temporary files, Delivery Optimization files, Recycle Bin, Windows Update Cleanup…).
- Click OK. From now on,
/sagerun:1always uses these choices.
🔍 What Each Line of the Script Does
| Line | What it does |
|---|---|
@echo off | Hides each command as it runs, keeping the output clean. |
del /s /f /q %temp%\* | Deletes the current user’s temporary folder contents — recursively through subfolders (/s), forced even on read-only files (/f) and without asking for confirmation (/q). |
del /s /f /q C:\Windows\Temp\* | Same logic, but in the system’s own temporary folder. |
cleanmgr /sagerun:1 | Runs Windows’ built-in Disk Cleanup with the profile you configured, automating what would normally take several clicks. |
pause | Keeps the window open at the end so you can read “Done!” before it closes. |
Understanding each line matters twice over: you can trust what’s running on your machine, and you can explain it to a customer if you decide to offer this as a service.
🔥 Automation
Most people stop here: they run the script once, feel the improvement and forget it exists. Months later the junk is back. Automating solves that at the root:
- Open Task Scheduler from the Start menu
- Click Create Task (not “Basic Task”)
- On the General tab, tick Run with highest privileges
- On the Triggers tab, choose Weekly — for example Monday morning
- On the Actions tab, choose “Start a program” and point it to limpeza.bat

For the scheduled version, remove the pause line from a copy of the script — otherwise the window will sit there waiting for a key press that never comes.
💰 Turning It Into Income
This isn’t just a script — it’s the core of a service. You can offer cleaning, optimisation, monthly maintenance and remote support. With a handful of customers you already have recurring income.
“But if the script is free, why would anyone pay?” Because most people — especially those who aren’t comfortable with technology — don’t know it exists, don’t trust running a .bat file, and don’t have time to configure Task Scheduler. You’re not selling the script: you’re selling peace of mind, time saved and technical trust.

| Basic tool | Role in the service |
|---|---|
| Cleaning script (.bat) | The technical core of the service, free and open. |
| AnyDesk or TeamViewer | Remote access, so you don’t need to travel. |
| Health report (PowerShell / HWiNFO) | A before-and-after report proving the value delivered. |
| A simple spreadsheet | To track which customers got their monthly maintenance and when the next one is due. |
📋 Packaging and Pricing
- Define a clear package: for example “Monthly Preventive Maintenance” with temporary file cleanup, disk space check and a quick system health check.
- Document before and after: a screenshot of the space freed or the boot time before and after is far more convincing than “I cleaned your PC”.
- Charge for the value delivered, not just the time: a PC that’s fast again can be worth much more to the customer than the minutes the remote session took.
- Offer a recurring plan: a fixed monthly package is more attractive to the customer (predictable cost) and better for you (predictable income).
- Start with entry prices to build a portfolio: first customers generate testimonials and referrals, which are worth more in the long run.
🧰 Other Maintenance That Pairs With This Script
- Disk space analysis: tools like WizTree show what’s eating space beyond temporary files — forgotten downloads, old installer folders.
- Startup programs: many apps add themselves to startup and slow the boot. Review the list in Task Manager → Startup apps.
- Updates: keep Windows and programs up to date — Winget updates every program with one command, and drivers can be updated without paid tools.
- Hardware diagnosis: if the PC is still slow after cleaning, the cause may be physical — see 4 commands that show the PC’s real health.
- System file repair: if Windows itself is misbehaving, see SFC and DISM.
🔧 Common Errors When Running the Script
| Error | What to do |
|---|---|
| “Access denied” when running | The file wasn’t run as administrator. Right-click the .bat and choose “Run as administrator”. |
| Windows SmartScreen blocks it | Normal for .bat files downloaded from the internet. Open the file in Notepad, check the content, then click “More info” → “Run anyway”. |
| The window closes before I can read the result | Make sure the “pause” line is at the end of the script. |
| cleanmgr doesn’t open any window | Expected — with /sagerun it runs silently in the background. |
| Almost nothing was freed | Check that you created the profile with cleanmgr /sageset:1 and ticked the categories. |
FAQ
Does the script delete personal files like photos and documents?
No. It only acts on temporary folders (%temp% and C:\Windows\Temp) and Windows’ built-in Disk Cleanup. Documents, photos and saved passwords are not affected — just be careful not to tick “Downloads” in the Disk Cleanup profile if you keep files there.
Why create a restore point before running the script?
It’s an extra professional safety layer: if anything turns out differently than expected, you can roll the system settings back quickly.
How do I make the script run automatically every week?
Use Task Scheduler: create a task with “Run with highest privileges”, a weekly trigger, and an action pointing to limpeza.bat.
Do I need to know programming to use it?
No. Copy the code exactly as it is, paste it into Notepad, save it with the .bat extension and run it as administrator.
Can you really earn money offering this kind of service?
Yes, it’s a real IT maintenance service. The key is packaging the offer well (cleaning + optimisation + recurring maintenance) and getting the first customers through referrals or social media.
SmartScreen blocked my script — is it a virus?
Not necessarily. It’s Windows’ default behaviour for any .bat downloaded from the internet. Open it in Notepad and review the content before allowing it to run.
🎮 How much did you learn?
Once you pick an answer it locks in — reload the page to try again.
1. What does “del /s /f /q %temp%\*” do in the script?
2. Why create a restore point before running the cleanup script?
3. What must you run once so cleanmgr /sagerun:1 knows what to clean?
4. How do you automate the script every week?
5. According to the article, how can this skill become income?
Esse conteúdo ajudou você?
Compartilha com alguém que também vai curtir — é rapidinho e ajuda muito o nosso trabalho a chegar em mais gente.
Conhecimento só tem valor quando compartilhado.
Manter essa estrutura de laboratórios funcionando e produzir conteúdos de engenharia de forma totalmente gratuita e acessível exige tempo e dedicação diária à bancada. Esse guia salvou os seus arquivos? Você pode contribuir diretamente para manter o nosso trabalho independente forte. Apoie doando qualquer valor!
Quer apoiar a nossa bancada independente?
[email protected]