From d8a7cb7c1245d7031fe96db82afe13cb811126ea Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sun, 22 May 2022 17:24:56 +0200 Subject: [PATCH] Completed uninstall feature --- Winget-AutoUpdate-Install.ps1 | 10 +++++++--- Winget-AutoUpdate/WAU-Uninstall.ps1 | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Winget-AutoUpdate/WAU-Uninstall.ps1 diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 84bc570..81ba2ee 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -247,18 +247,22 @@ function Install-WingetAutoUpdate{ function Uninstall-WingetAutoUpdate{ try{ + #Get registry install location + $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation + #Check if installed location exists and delete - if (Test-Path ($WingetUpdatePath)){ - Remove-Item $WingetUpdatePath -Force -Recurse + if (Test-Path ($InstallLocation)){ + Remove-Item $InstallLocation -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 + & reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null Write-host "Uninstallation succeeded!" -ForegroundColor Green Start-sleep 1 } else { - Write-host "$WingetUpdatePath not found! Uninstallation failed!" -ForegroundColor Red + Write-host "$InstallLocation not found! Uninstallation failed!" -ForegroundColor Red } } catch{ diff --git a/Winget-AutoUpdate/WAU-Uninstall.ps1 b/Winget-AutoUpdate/WAU-Uninstall.ps1 new file mode 100644 index 0000000..1d05b84 --- /dev/null +++ b/Winget-AutoUpdate/WAU-Uninstall.ps1 @@ -0,0 +1,23 @@ +try{ + #Get registry install location + $InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation + + #Check if installed location exists and delete + if (Test-Path ($InstallLocation)){ + Remove-Item $InstallLocation -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 + & reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null + + Write-host "Uninstallation succeeded!" -ForegroundColor Green + Start-sleep 1 + } + else { + Write-host "$InstallLocation not found! Uninstallation failed!" -ForegroundColor Red + } +} +catch{ + Write-host "`nUninstallation failed! Run as admin ?" -ForegroundColor Red + Start-sleep 1 +} \ No newline at end of file