diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs index 620e30c1fd..187a012233 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs @@ -32,30 +32,27 @@ public class ChocolateyUninstallTemplate ## - https://chocolatey.org/docs/helpers-uninstall-chocolatey-package $ErrorActionPreference = 'Stop'; # stop on all errors - -$packageName = '[[PackageName]]' -$softwareName = '[[PackageName]]*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique -$installerType = 'MSI' -#$installerType = 'EXE' - -$silentArgs = '/qn /norestart' -# https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx -$validExitCodes = @(0, 3010, 1605, 1614, 1641) -if ($installerType -ne 'MSI') { - # The below is somewhat naive and built for EXE installers +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + softwareName = '[[PackageName]]*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique + fileType = '[[InstallerType]]' #only one of these: MSI or EXE (ignore MSU for now) + # MSI + silentArgs = ""/qn /norestart"" + validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx + # OTHERS # Uncomment matching EXE type (sorted by most to least common) - #$silentArgs = '/S' # NSIS - #$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup - #$silentArgs = '/s' # InstallShield - #$silentArgs = '/s /v""/qn""' # InstallShield with MSI - #$silentArgs = '/s' # Wise InstallMaster - #$silentArgs = '-s' # Squirrel - #$silentArgs = '-q' # Install4j - #$silentArgs = '-s -u' # Ghost + #silentArgs = '/S' # NSIS + #silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup + #silentArgs = '/s' # InstallShield + #silentArgs = '/s /v""/qn""' # InstallShield with MSI + #silentArgs = '/s' # Wise InstallMaster + #silentArgs = '-s' # Squirrel + #silentArgs = '-q' # Install4j + #silentArgs = '-s -u' # Ghost # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence. - #$silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) - # https://chocolatey.org/packages/autohotkey.portable - $validExitCodes = @(0) + #silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) + # https://chocolatey.org/packages/autohotkey.portable + #validExitCodes= @(0) #please insert other valid exit codes here } $uninstalled = $false @@ -64,29 +61,24 @@ public class ChocolateyUninstallTemplate # This is only a fuzzy search if $softwareName includes '*'. Otherwise it is # exact. In the case of versions in key names, we recommend removing the version # and using '*'. -[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName +[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName'] if ($key.Count -eq 1) { $key | % { - $file = ""$($_.UninstallString)"" - - if ($installerType -eq 'MSI') { + $packageArgs['file'] = ""$($_.UninstallString)"" + if ($packageArgs['fileType'] -eq 'MSI') { # The Product Code GUID is all that should be passed for MSI, and very # FIRST, because it comes directly after /x, which is already set in the # Uninstall-ChocolateyPackage msiargs (facepalm). - $silentArgs = ""$($_.PSChildName) $silentArgs"" - + $packageArgs['silentArgs'] = ""$($_.PSChildName) $($packageArgs['silentArgs'])"" + # Don't pass anything for file, it is ignored for msi (facepalm number 2) # Alternatively if you need to pass a path to an msi, determine that and # use it instead of the above in silentArgs, still very first - $file = '' + $packageArgs['file'] = '' } - Uninstall-ChocolateyPackage -PackageName $packageName ` - -FileType $installerType ` - -SilentArgs ""$silentArgs"" ` - -ValidExitCodes $validExitCodes ` - -File ""$file"" + Uninstall-ChocolateyPackage @packageArgs } } elseif ($key.Count -eq 0) { Write-Warning ""$packageName has already been uninstalled by other means.""