packages/chocolatey/tools/chocolateyuninstall.ps1 78 lines View on github.com → Search inside
1# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:2#   $f='c:\path\to\thisFile.ps1'3#   gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f45## NOTE: In 80-90% of the cases (95% with licensed versions due to Package Synchronizer and other enhancements),6## AutoUninstaller should be able to detect and handle registry uninstalls without a chocolateyUninstall.ps1.7## See https://chocolatey.org/docs/commands-uninstall8## and https://chocolatey.org/docs/helpers-uninstall-chocolatey-package910## If this is an MSI, ensure 'softwareName' is appropriate, then clean up comments and you are done.11## If this is an exe, change fileType, silentArgs, and validExitCodes1213$ErrorActionPreference = 'Stop'; # stop on all errors14$packageArgs = @{15  packageName   = $env:ChocolateyPackageName16  softwareName  = 'scc*'  #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique17  fileType      = 'EXE_MSI_OR_MSU' #only one of these: MSI or EXE (ignore MSU for now)18  # MSI19  silentArgs    = "/qn /norestart"20  validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx21  # OTHERS22  # Uncomment matching EXE type (sorted by most to least common)23  #silentArgs   = '/S'           # NSIS24  #silentArgs   = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup25  #silentArgs   = '/s'           # InstallShield26  #silentArgs   = '/s /v"/qn"'   # InstallShield with MSI27  #silentArgs   = '/s'           # Wise InstallMaster28  #silentArgs   = '-s'           # Squirrel29  #silentArgs   = '-q'           # Install4j30  #silentArgs   = '-s -u'        # Ghost31  # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.32  #silentArgs   = ''             # none; make silent with input macro script like AutoHotKey (AHK)33                                 #       https://chocolatey.org/packages/autohotkey.portable34  #validExitCodes= @(0) #please insert other valid exit codes here35}3637$uninstalled = $false38# Get-UninstallRegistryKey is new to 0.9.10, if supporting 0.9.9.x and below,39# take a dependency on "chocolatey-core.extension" in your nuspec file.40# This is only a fuzzy search if $softwareName includes '*'. Otherwise it is 41# exact. In the case of versions in key names, we recommend removing the version42# and using '*'.43[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName']4445if ($key.Count -eq 1) {46  $key | % { 47    $packageArgs['file'] = "$($_.UninstallString)"48    if ($packageArgs['fileType'] -eq 'MSI') {49      # The Product Code GUID is all that should be passed for MSI, and very 50      # FIRST, because it comes directly after /x, which is already set in the 51      # Uninstall-ChocolateyPackage msiargs (facepalm).52      $packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])"53      54      # Don't pass anything for file, it is ignored for msi (facepalm number 2) 55      # Alternatively if you need to pass a path to an msi, determine that and 56      # use it instead of the above in silentArgs, still very first57      $packageArgs['file'] = ''58    }5960    Uninstall-ChocolateyPackage @packageArgs61  }62} elseif ($key.Count -eq 0) {63  Write-Warning "$packageName has already been uninstalled by other means."64} elseif ($key.Count -gt 1) {65  Write-Warning "$($key.Count) matches found!"66  Write-Warning "To prevent accidental data loss, no programs will be uninstalled."67  Write-Warning "Please alert package maintainer the following keys were matched:"68  $key | % {Write-Warning "- $($_.DisplayName)"}69}7071## OTHER POWERSHELL FUNCTIONS72## https://chocolatey.org/docs/helpers-reference73#Uninstall-ChocolateyZipPackage $packageName # Only necessary if you did not unpack to package directory - see https://chocolatey.org/docs/helpers-uninstall-chocolatey-zip-package74#Uninstall-ChocolateyEnvironmentVariable # 0.9.10+ - https://chocolatey.org/docs/helpers-uninstall-chocolatey-environment-variable 75#Uninstall-BinFile # Only needed if you used Install-BinFile - see https://chocolatey.org/docs/helpers-uninstall-bin-file76## Remove any shortcuts you added in the install script.

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.