5 Ways To Clean Up Your Computer With An Automated Script [Windows]

Ads by Google

automate computer cleanupComputer maintenance isn’t exactly something that most people remember to do. For the general user that isn’t exactly tech savvy, when a computer doesn’t work, they either call for help or simply buy a new computer.

If you have family members or friends that are always calling you for help with a slow computer, I’m going to offer you a solution that you can use to stop those phone calls right now. This solution incorporates six tools into a Windows script. That script is going to perform all of the PC cleanup work that you would do if you were sitting right in front of the computer yourself.

What This Script Will Accomplish

This Windows script is going to run the required tools in command line mode. Many of these tools that you’ve been using for years, you may not have even realized that there is a command-line mode available.

Clean Up Registry & Temp Folders

The first step is probably the most important. We’re going to launch CCleaner in command line mode to clean up temp files and the registry.

One catch. In order to make this script work without constant notifications about the apps making computer changes, you’ll have to disable the User Account Control windows feature in Windows 7.

Ads by Google

Now you’re ready to roll. Create a file called CleanComputer.wsf and start it off with the following script.

<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
Dim retVal
set WshShell=CreateObject("WScript.Shell")
WshShell.run "CCleaner.exe /AUTO"

Danny covered CCleaner recently, so you can see just what it is capable of and how much it can optimize your system. When you launch it in the script as shown above with the /AUTO flag, it’ll run invisible and it’ll use the settings you used when you last ran the application. You’ll see CCleaner.exe running in the Task Manager.

automate computer cleanup

If you configure CCleaner beforehand, in auto mode it’ll automatically clean up temporary files, log files and your registry as well.

Clean Up Spyware

Next up is to take care of any spyware that might be running on the PC. My favorite tool for that is Spybot, and luckily Spybot also offers a command line feature. The one problem here is that the path to Spybot is full of spaces, which is hard to handle in a Windows Script shell command.

So, create a .bat file with the following:

C:\Program Files (x86)\Spybot - Search & Destroy\SpybotSD.exe" /taskbarhide /autocheck /autofix /autoclose

Save it as SpyBot.bat in the same directory as your Windows script. Then in the next line of your WSF file, add the following:

WshShell.run "spybot.bat"

Your Windows Script will launch your batch job that will launch Spybot in command-line mode. You will know it’s running when the Exe appears in the task manager.

script to clean temp files

Those four parameters after the spybotsd.exe file  will run Spybot in silent mode, automatically remove any spyware found, and then automatically close.

Remove Malicious Software

In addition to anything Spybot catches, I also like to run the Microsoft Malicious Software removal tool. Download the executable from the “Microsoft Download Center” section, save it in your script directory as “malremove.exe” and then add the following line to your growing Windows Script.

WshShell.run "malremove.exe /Q /F:Y"

The /Q command tells the malware removal tool to run in quiet mode (no interface) and /F:Y tells it to forcibly remove any malware that it finds without any intervention required. The first time you run it during your initial testing, you’ll have to select the option for no warning the next time it runs.

script to clean temp files

Here it is running in the background.

script to clean temp files

So, we’ve covered most of what you’d probably do if you were there in person – run CCleaner to get rid of temporary Internet files and other temp files, remove spyware and malware, so what’s left?

Automate Disk Cleanup

Another common tool that can help computer performance is the Windows Disk Cleanup tool.  First you have to set it up. Go to Start -> Run and type: “cleanmgr /sageset:1“. The following window will appear.

computer clean up script

Set up the items that you’d like your command line to automatically clean, and then click OK. This tells it that whenever you choose /sageset:1, to utilize the settings you’ve just created. Now, in your Windows Script, add the following line.

WshShell.run "Cleanmgr /sagerun:1"

This will run the Windows disk cleanup silently, using the settings you’ve just created. You can also install the latest Windows updates by first installing WuInstall.exe and adding this line.

WshShell.run "wuinstall.exe /install /reboot_if_needed"

And don’t forget to do a quick defrag of the hard drive by adding the following lines to the script.

WshShell.run “Defrag volume c:”

WshShell.run "Defrag volume d:"

Automate Virus Scan After Cleanup

Last, but definitely not least, you’ll also want to end your script by firing off a full virus scan. For example, I use Kaspersky, which offers its own set of command line parameters.

In my case, I just add the following final line to my script.

WshShell.run "AVP.exe SCAN /ALL /i4"

And that kicks off the command window and runs through a full scan (which can take several hours).

automate computer cleanup

Most other anti-virus providers out there offer similar command-line options.

So, once you’ve added all of these lines, close out your Windows Script.


Once you’ve finished the procedure above and saved your file on the PC, just schedule the job to run on a regular basis (/Accessories/System Tools/Task Scheduler). Give the procedure above a try and see how well it works for you.

Did it work well, and can you think of any other useful command line tasks that could also be added? Share your thoughts in the comments section below.

Image Credit: Shutterstock

Join live MakeUseOf Groups on Grouvi App Join live Groups on Grouvi
Windows Tips
Windows Tips
678 Members
538 Members
Windows Troubleshooting
Windows Troubleshooting
462 Members
Best Windows Software
Best Windows Software
399 Members
Computer Hardware Talk
Computer Hardware Talk
281 Members
Affiliate Disclamer

This article may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
New comment

Please login to avoid entering captcha

Log In