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..7a49967 100644 --- a/README.md +++ b/README.md @@ -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`. -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: diff --git a/WindowsClearCache.nsi b/WindowsClearCache.nsi new file mode 100644 index 0000000..cf8c747 --- /dev/null +++ b/WindowsClearCache.nsi @@ -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' + SkipTask: +SectionEnd + +Section "Uninstall" + nsExec::ExecToLog 'schtasks /Delete /TN "WindowsClearCache" /F' + Delete "$INSTDIR\\DriveClean.ps1" + Delete "$INSTDIR\\Uninstall.exe" + RMDir "$INSTDIR" +SectionEnd