Skip to content

Commit

Permalink
(GH-296) Enhance Uninstall Template
Browse files Browse the repository at this point in the history
From the get go, the uninstall template is broken for MSI packages.
Provide the best guidance on how to find the uninstaller registry key
based on similarities to what @AnthonyMastrean created for uninstalling
packages.
  • Loading branch information
ferventcoder committed May 30, 2015
1 parent 636d601 commit fd35ab2
Showing 1 changed file with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,63 @@ public class ChocolateyUninstallTemplate
# stop on all errors
$ErrorActionPreference = 'Stop';
# REMOVE ANYTHING BELOW THAT IS NOT NEEDED
# Auto Uninstaller should be able to detect and handle registry uninstalls (if it is turned on, it is in preview for 0.9.9).
$packageName = '[[PackageName]]'
# registry uninstaller key name is the key that is found at HKLM:\Software\Windows\CurrentVersion\Uninstall\ THE NAME
$registryUninstallerKeyName = '[[PackageName]]' #ensure this is the value in the registry
$installerType = 'EXE'
$silentArgs = '/S'
$validExitCodes = @(0)
#$osBitness = Get-ProcessorBits
#if ($osBitness -eq 64) {
# $file = (Get-ItemProperty -Path ""hklm:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName"").UninstallString
#} else {
# $file = (Get-ItemProperty -Path ""hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName"").UninstallString
#}
#
#Uninstall-ChocolateyPackage -PackageName $packageName -FileType $installerType -SilentArgs $silentArgs -validExitCodes $validExitCodes -File $file
$msiProductCodeGuid = '{insert it here}'
$local_key = ""HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName""
# local key 6432 probably never exists
$local_key6432 = ""HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName""
$machine_key = ""HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName""
$machine_key6432 = ""HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$registryUninstallerKeyName""
$file = @($local_key, $local_key6432, $machine_key, $machine_key6432) `
| ?{ Test-Path $_ } `
| Get-ItemProperty `
| Select-Object -ExpandProperty UninstallString
if ($file -eq $null -or $file -eq '') {
Write-Host ""$packageName has already been uninstalled by other means.""
$shouldUninstall = $false
}
# The below is somewhat naive and built for EXE installers
#$installerType = 'EXE'
#$silentArgs = '/S'
#$validExitCodes = @(0)
#if (!(Test-Path $file)) {
# Write-Host ""$packageName has already been uninstalled by other means.""
# $shouldUninstall = $false
#}
# The below is somewhat naive and built for MSI installers
$installerType = '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 = ""$msiProductCodeGuid /qn /norestart""
# https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx
$validExitCodes = @(0, 3010, 1614, 1641)
# 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 $msiProductCodeGuid in silentArgs, still very first
$file = ''
if ($shouldUninstall) {
Uninstall-ChocolateyPackage -PackageName $packageName -FileType $installerType -SilentArgs $silentArgs -validExitCodes $validExitCodes -File $file
}
## OTHER HELPERS
## https://github.com/chocolatey/choco/wiki/HelpersReference
#Uninstall-ChocolateyZipPackage
#Uninstall-BinFile # Only needed if you added one in the installer script, choco will remove the ones it added automatically.
#remove any shortcuts you added
";
}
}

0 comments on commit fd35ab2

Please sign in to comment.