Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/build-installer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build Installer

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install NSIS
run: choco install nsis -y
- name: Build installer
run: makensis WindowsClearCache.nsi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: WindowsClearCacheInstaller
path: WindowsClearCacheInstaller.exe
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WindowsClearCacheInstaller.exe
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# WindowsClearCache

Simple scripts to clear temp files, browser cache/history, caches for applications like Microsoft Teams, Slack, Discord, Opera, and OneDrive, and remove Windows Defender scan and definition update backups (including the NisBackup folder), Windows dump files, and Windows Error Reporting (WER) temp files
Simple scripts to clear temp files, browser cache/history, caches for applications like Microsoft Teams, Slack, Discord, Opera,
and OneDrive, and remove Windows Defender scan and definition update backups (including the NisBackup folder), Windows dump files, and Windows Error Reporting (WER) temp files

## How To Run
## Installation

1) Build the graphical installer by running `makensis WindowsClearCache.nsi` (or download a pre-built `WindowsClearCacheInstaller.exe`).
2) Run `WindowsClearCacheInstaller.exe` as an administrator.
- The installer launches `cleanmgr.exe /sageset:1` so you can configure Disk Cleanup before the first run.
- You can choose to create a weekly scheduled task that runs the cleanup with highest privileges.
- The cleaner script is copied to `c:\Program Files\WindowsClearCache`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path c:\Program Files is hardcoded. This path can be different on non-English versions of Windows or on systems where it has been moved. It's better to use the environment variable %ProgramFiles% to be more accurate, especially since the NSIS script correctly uses the $PROGRAMFILES variable.

Suggested change
- The cleaner script is copied to `c:\Program Files\WindowsClearCache`.
- The cleaner script is copied to `%ProgramFiles%\WindowsClearCache`.


To run this with parameters, do the following:
## How To Run

1) Download the .zip file on the main page of the GitHub and extract the .zip file to your desired location, e.g. - `c:\WindowsClearCache`
2) Once extracted, open [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting) (or [PowerShell ISE](https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/ise/introducing-the-windows-powershell-ise)) as an Administrator
3) Enable PowerShell execution: `Set-ExecutionPolicy Unrestricted -Force` (to allow executing unsigned code)
4) Run the Disk Cleanup utility (cleanmgr.exe) with the /sageset:1 option, which allows users to configure cleanup settings before executing the actual cleanup process
e.g. - `cleanmgr.exe /sageset:1`
5) On the prompt, change to the directory where you extracted the files:
e.g. - `cd c:\Program Files\WindowsClearCache`
6) Next, to run the script, enter in the following:
e.g. - `.\DriveClean.ps1`
After installation you can run the cleaner manually with:
`powershell.exe -ExecutionPolicy Bypass -File "%ProgramFiles%\WindowsClearCache\DriveClean.ps1"`

Optional flags:

- Use `-DryRun` to preview the files that would be deleted without removing them.
- Use `-Verbose` to display each file as it is deleted (or would be deleted in dry run).

## Uninstallation

Run `Uninstall.exe` from `c:\Program Files\WindowsClearCache` or use Add/Remove Programs. This removes the scheduled task and deletes the installed files.

## Tested on following Windows Versions

Verified on the following platforms:
Expand Down
33 changes: 33 additions & 0 deletions WindowsClearCache.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
!include "MUI2.nsh"

Name "Windows Clear Cache"
OutFile "WindowsClearCacheInstaller.exe"
InstallDir "$PROGRAMFILES\\WindowsClearCache"
RequestExecutionLevel admin

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "Install"
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\\Uninstall.exe"
File "DriveClean.ps1"

DetailPrint "Open Disk Cleanup configuration"
nsExec::ExecToLog 'cleanmgr.exe /sageset:1'

MessageBox MB_YESNO "Create a weekly scheduled cleanup task?" IDNO SkipTask
nsExec::ExecToLog 'schtasks /Create /TN "WindowsClearCache" /TR "powershell.exe -ExecutionPolicy Bypass -File \\\"$INSTDIR\\DriveClean.ps1\\\"" /SC WEEKLY /RL HIGHEST /F'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The quoting for the file path in the schtasks command appears to be incorrect. The \\\" will likely result in a literal \\" being passed in the command, which will cause the scheduled task to fail. For schtasks, inner quotes within the /TR argument should be escaped with a single backslash (\").

  nsExec::ExecToLog 'schtasks /Create /TN "WindowsClearCache" /TR "powershell.exe -ExecutionPolicy Bypass -File \"$INSTDIR\\DriveClean.ps1\"" /SC WEEKLY /RL HIGHEST /F'

SkipTask:
SectionEnd

Section "Uninstall"
nsExec::ExecToLog 'schtasks /Delete /TN "WindowsClearCache" /F'
Delete "$INSTDIR\\DriveClean.ps1"
Delete "$INSTDIR\\Uninstall.exe"
RMDir "$INSTDIR"
SectionEnd
Loading