From 559eca32d2289a9ae46c0391d60358791a06dc0c Mon Sep 17 00:00:00 2001 From: Francisco Javier Date: Mon, 8 Sep 2025 19:44:02 +0200 Subject: [PATCH 1/3] Add GitHub workflow to build NSIS installer --- .github/workflows/build-installer.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + README.md | 24 ++++++++++++------------ WindowsClearCache.nsi | 23 +++++++++++++++++++++++ 4 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/build-installer.yml create mode 100644 .gitignore create mode 100644 WindowsClearCache.nsi diff --git a/.github/workflows/build-installer.yml b/.github/workflows/build-installer.yml new file mode 100644 index 0000000..45d3349 --- /dev/null +++ b/.github/workflows/build-installer.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7f81dc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +WindowsClearCacheInstaller.exe diff --git a/README.md b/README.md index a59cbd3..e67a7c6 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # 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 + +## 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`. ## How To Run -To run this with parameters, do the following: - -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: +`c:\Program Files\WindowsClearCache\DriveClean.ps1` Optional flags: diff --git a/WindowsClearCache.nsi b/WindowsClearCache.nsi new file mode 100644 index 0000000..5c3bdfe --- /dev/null +++ b/WindowsClearCache.nsi @@ -0,0 +1,23 @@ +!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_LANGUAGE "English" + +Section "Install" + SetOutPath "$INSTDIR" + 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' +SkipTask: +SectionEnd From 7cd02a48ff6dfa09821b963ed457f92370070b6d Mon Sep 17 00:00:00 2001 From: Francisco Javier Date: Mon, 8 Sep 2025 20:12:49 +0200 Subject: [PATCH 2/3] Add uninstaller to remove scheduled task and files --- README.md | 4 ++++ WindowsClearCache.nsi | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e67a7c6..dd10e40 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,10 @@ 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: diff --git a/WindowsClearCache.nsi b/WindowsClearCache.nsi index 5c3bdfe..cf8c747 100644 --- a/WindowsClearCache.nsi +++ b/WindowsClearCache.nsi @@ -8,10 +8,13 @@ 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" @@ -19,5 +22,12 @@ Section "Install" 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' -SkipTask: + SkipTask: +SectionEnd + +Section "Uninstall" + nsExec::ExecToLog 'schtasks /Delete /TN "WindowsClearCache" /F' + Delete "$INSTDIR\\DriveClean.ps1" + Delete "$INSTDIR\\Uninstall.exe" + RMDir "$INSTDIR" SectionEnd From fe78daf300108ad7f925bb5fb146f42aea712568 Mon Sep 17 00:00:00 2001 From: Francisco Javier Date: Mon, 8 Sep 2025 20:24:41 +0200 Subject: [PATCH 3/3] Update README.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd10e40..7a49967 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ and OneDrive, and remove Windows Defender scan and definition update backups (in ## How To Run After installation you can run the cleaner manually with: -`c:\Program Files\WindowsClearCache\DriveClean.ps1` +`powershell.exe -ExecutionPolicy Bypass -File "%ProgramFiles%\WindowsClearCache\DriveClean.ps1"` Optional flags: