1- $packageName = ' msiafterburner'
2- $installerType = ' exe'
1+ $ErrorActionPreference = ' Stop' ;
2+
3+ $packageName = $env: ChocolateyPackageName
4+ $software = @ (' MSI Afterburner*' , ' RivaTuner Statistics Server*' )
35$silentArgs = ' /S'
4- $validExitCodes = @ (0 )
56$scriptPath = " $ ( Split-Path - parent $MyInvocation.MyCommand.Definition ) "
67$ahkFile = Join-Path $scriptPath ' chocolateyUninstall.ahk'
78$ahkExe = ' AutoHotKey'
89$ahkRun = " $Env: Temp \$ ( Get-Random ) .ahk"
9- $packageSearchRegex = ' ^(MSI Afterburner|RivaTuner Statistics Server).*'
10-
11- $toolsPath = Split-Path $MyInvocation.MyCommand.Definition
12- . $toolsPath \helpers.ps1
13-
14- Stop-Afterburner
1510
1611Copy-Item $ahkFile " $ahkRun " - Force
1712Start-Process $ahkExe $ahkRun
1813
19- Get-ItemProperty `
20- - Path @ (' HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' ,
21- ' HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ,
22- ' HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
23- - ErrorAction:SilentlyContinue `
24- | Where-Object `
25- {$_.DisplayName -Match $packageSearchRegex } `
26- | ForEach-Object `
27- {Uninstall-ChocolateyPackage `
28- - PackageName " $packageName " `
29- - FileType " $installerType " `
30- - SilentArgs " $ ( $silentArgs ) " `
31- - File " $ ( $_.UninstallString.Replace (' "' , ' ' )) " `
32- - ValidExitCodes $validExitCodes }
14+ For ($i = 0 ; $i -lt $software.Length ; $i ++ ) {
15+ [array ]$key = Get-UninstallRegistryKey - SoftwareName $software [$i ]
16+
17+ if ($key.Count -eq 1 ) {
18+ $key | ForEach-Object {
19+ $file = $ ($_.UninstallString )
20+ Start-Process $file - ArgumentList $silentArgs - Verb RunAs
21+ }
22+ } elseif ($key.Count -eq 0 ) {
23+ Write-Warning " $packageName has already been uninstalled by other means."
24+ } elseif ($key.Count -gt 1 ) {
25+ Write-Warning " $key .Count matches found!"
26+ Write-Warning " To prevent accidental data loss, no programs will be uninstalled."
27+ Write-Warning " Please alert package maintainer(s) the following keys were matched:"
28+ $key | ForEach-Object {Write-Warning " - $_ .DisplayName" }
29+ }
30+ }
3331
3432Remove-Item " $ahkRun " - Force
0 commit comments