Last active
August 29, 2015 14:22
-
-
Save ferventcoder/c6e446187d96a2436a09 to your computer and use it in GitHub Desktop.
New Chocolatey Uninstall Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NOTE: Please remove any commented lines to tidy up prior to releasing the package, including this one | |
# 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 | |
$msiProductCodeGuid = '{insert it here}' | |
$shouldUninstall = $true | |
$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, 1605, 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment