LOGO

Automated Computer Cleanup: 5 Scripting Methods for Windows

October 26, 2011
Automated Computer Cleanup: 5 Scripting Methods for Windows

The Often-Overlooked Importance of Computer Maintenance

Regular computer maintenance is frequently neglected by many users. Individuals who aren't particularly familiar with technology often resort to seeking assistance or purchasing a replacement when their computer malfunctions.

Do you find yourself consistently assisting family and friends with sluggish computers? A readily available solution exists to curtail these requests for support.

Introducing an Automated PC Cleanup Solution

This solution leverages the power of six distinct tools integrated into a single Windows script. The script effectively executes all the PC cleanup tasks one would typically perform manually while physically present at the computer.

This automated approach streamlines the maintenance process, offering a convenient way to optimize performance and resolve common issues.

Benefits of Utilizing a Maintenance Script

  • Reduced Support Requests: Minimize the number of calls for technical assistance.
  • Proactive Problem Solving: Address potential issues before they escalate.
  • Simplified Maintenance: Eliminate the need for manual intervention and technical expertise.
  • Improved Performance: Enhance the speed and responsiveness of the computer.

By implementing this script, users can proactively maintain their systems, leading to a more stable and efficient computing experience. It provides a practical alternative to frequent hardware replacements.

Automating Computer Maintenance with a Windows Script

This script is designed to execute essential system maintenance tools via the command line. Many applications possess command-line interfaces that are often overlooked by users familiar with graphical user interfaces.

Registry and Temporary File Cleanup

The initial phase focuses on cleaning the system registry and temporary folders, a crucial step for optimal performance. This will be achieved by launching CCleaner in command-line mode.

It's important to note that disabling User Account Control (UAC) in Windows 7 may be necessary to prevent constant prompts regarding application changes during script execution.

xx-ways-clean-computer-automated-script-1.jpg

To begin, create a file named CleanComputer.wsf and populate it with the following script code.

<job>

<script language="VBScript">

Option Explicit

On Error Resume Next

Dim WshShell

Dim retVal

set WshShell=CreateObject("WScript.Shell")

WshShell.run "CCleaner.exe /AUTO"

As previously detailed, CCleaner offers extensive optimization capabilities. Utilizing the /AUTO flag initiates the application invisibly, employing the settings last used within the graphical interface. The process will be visible within the Task Manager.

xx-ways-clean-computer-automated-script-2.jpg

Prior configuration of CCleaner is key; in automatic mode, it will systematically clear temporary files, log files, and registry entries.

Spyware Removal

The next step involves eliminating potential spyware infections. Spybot – Search & Destroy is a preferred tool for this purpose, and it also supports command-line operation. A challenge arises due to the spaces within the Spybot installation path, which can complicate scripting.

Therefore, a .bat file containing the following command should be created:

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

Exit

Save this file as SpyBot.bat in the same directory as the Windows script. Subsequently, add the following line to your WSF file:

WshShell.run "spybot.bat"

The Windows Script will then execute the batch file, launching Spybot in command-line mode. Its operation will be indicated by its presence in the Task Manager.

xx-ways-clean-computer-automated-script-3.jpg

These parameters instruct Spybot to run silently, automatically remove detected spyware, and then close automatically.

Malware Elimination

Beyond Spybot's capabilities, the Microsoft Malicious Software Removal Tool is also recommended. Download the executable from the Microsoft Download Center, save it as "malremove.exe" in the script directory, and add this line to your Windows Script:

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

The /Q flag enables quiet mode, suppressing the user interface, while /F:Y forces malware removal without requiring user intervention. The initial execution may prompt a warning option to disable for subsequent runs.

xx-ways-clean-computer-automated-script-4.jpg

The tool will run in the background as shown.

xx-ways-clean-computer-automated-script-5.jpg

Having addressed temporary files, spyware, and malware, what further steps can be taken?

Disk Cleanup Automation

The Windows Disk Cleanup tool is another valuable asset for maintaining system performance. First, configure it by navigating to Start -> Run and entering: "cleanmgr /sageset:1". This will open a configuration window.

xx-ways-clean-computer-automated-script-6.jpg

Select the items you wish to automatically clean, then click OK. This establishes the settings for use with the /sageset:1 parameter. Add the following line to your Windows Script:

WshShell.run "Cleanmgr /sagerun:1"

This will execute Windows Disk Cleanup silently, utilizing your predefined settings. Furthermore, you can automate Windows updates by installing WuInstall.exe and adding this line:

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

Finally, defragment the hard drives by adding these lines to the script:

WshShell.run "Defrag volume c:"

WshShell.run "Defrag volume d:"

Automated Virus Scan

To conclude, schedule a full virus scan. I utilize Kaspersky, which provides command-line parameters.

Add the following line to your script:

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

This initiates a full scan, which may take several hours, within a command window.

xx-ways-clean-computer-automated-script-7.jpg

Most antivirus providers offer comparable command-line options.

Once all lines are added, close the Windows Script.

WScript.Quit

</script>

</job>

Save the file and schedule the job to run regularly using the Task Scheduler (/Accessories/System Tools/Task Scheduler). Experiment with this procedure and assess its effectiveness.

How did it perform? Can you envision other useful command-line tasks to incorporate? Share your insights in the comments below.

Image Credit: Shutterstock

#Windows#computer cleanup#automated script#script#performance#disk space