From 648e2a252ed2eae4dd328eee3aa0f48b96b07437 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sat, 2 Apr 2022 19:24:18 +0200 Subject: [PATCH 1/2] Add uninstall parametre --- Winget-AutoUpdate-Install.ps1 | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 544d15e..6aa4a83 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -19,6 +19,9 @@ Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate i .PARAMETER DisableWAUAutoUpdate Disable Winget-AutoUpdate update checking. By default, WAU auto update if new version is available on Github. +.PARAMETER Uninstall +Remove scheduled tasks and scripts. + .EXAMPLE .\winget-install-and-update.ps1 -Silent -DoNotUpdate #> @@ -28,7 +31,8 @@ param( [Parameter(Mandatory=$False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", [Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false, - [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false + [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false, + [Parameter(Mandatory=$False)] [Switch] $Uninstall = $false ) @@ -143,6 +147,29 @@ function Install-WingetAutoUpdate{ } } +function Uninstall-WingetAutoUpdate{ + Write-Host "Starting uninstall" + try{ + #Check if installed location exists and delete + if (Test-Path ($WingetUpdatePath)){ + Remove-Item $WingetUpdatePath -Force -Recurse + Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False + Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False + & reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null + + Write-host "Uninstallation succeeded!" -ForegroundColor Green + Start-sleep 1 + } + else { + Write-host "$WingetUpdatePath not found! Uninstallation failed!" -ForegroundColor Red + } + } + catch{ + Write-host "`nUninstallation failed! Run as admin ?" -ForegroundColor Red + Start-sleep 1 + } +} + function Start-WingetAutoUpdate{ #If -DoNotUpdate is true, skip. if (!($DoNotUpdate)){ @@ -160,6 +187,9 @@ function Start-WingetAutoUpdate{ try{ Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue + while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') { + Start-Sleep 1 + } } catch{ Write-host "Failed to run Winget-AutoUpdate..." -ForegroundColor Red @@ -179,11 +209,15 @@ Write-host "# #" Write-host "# Winget AutoUpdate #" Write-host "# #" Write-host "###################################`n" -Write-host "Installing to $WingetUpdatePath\" -Install-Prerequisites - -Install-WingetAutoUpdate +if (!$Uninstall){ + Write-host "Installing to $WingetUpdatePath\" + Install-Prerequisites + Install-WingetAutoUpdate +} +else { + Uninstall-WingetAutoUpdate +} Write-host "End of process." Start-Sleep 3 From 5866aa7e132755a25d80589d6be6e2890da1449a Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sun, 3 Apr 2022 00:29:35 +0200 Subject: [PATCH 2/2] Create uninstall.bat --- uninstall.bat | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 uninstall.bat diff --git a/uninstall.bat b/uninstall.bat new file mode 100644 index 0000000..5e776d4 --- /dev/null +++ b/uninstall.bat @@ -0,0 +1,2 @@ +@echo off +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Uninstall'" -Verb RunAs