Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix packages using Get-ItemProperty to retrieve uninstall keys #198

Open
dtgm opened this issue May 21, 2016 · 0 comments
Open

Fix packages using Get-ItemProperty to retrieve uninstall keys #198

dtgm opened this issue May 21, 2016 · 0 comments

Comments

@dtgm
Copy link
Owner

dtgm commented May 21, 2016

Pre-fix

$packageName = '{{PackageName}}'
$packageSearch = "$packageName"
$installerType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
$validExitCodes = @(0)
try {
  Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
                            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
                            'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
                   -ErrorAction:SilentlyContinue `
  | Where-Object   { $_.DisplayName -like "$packageSearch*" } `
  | ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
                                                 -FileType "$installerType" `
                                                 -SilentArgs "$($silentArgs)" `
                                                 -File "$($_.UninstallString)" `
                                                 -ValidExitCodes $validExitCodes }
} catch {
  throw $_.Exception
}

ToDo

  • Add dependency to nuspec

no longer necessary as it was added as a native helper in 0.9.10-beta (chocolatey/choco@91db949)
Still necessary for backward compatibility until community packages require supporting >=0.9.10 (likely not until 2017)

<dependencies> 
  <dependency id="chocolatey-uninstall.extension" /> 
</dependencies>
  • Replace relevant lines in chocolateyUninstall.ps1
  • $packageSearch to $softwareName
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
                   'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
                   'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
                 -ErrorAction:SilentlyContinue `
| Where-Object   { $_.DisplayName -like "$packageSearch*" } `

to

[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
                                    -FileType "$installerType" `
                                    -SilentArgs "$($silentArgs)" `
                                    -File "$($_.UninstallString)" `
                                    -ValidExitCodes $validExitCodes }

to

$key | ForEach-Object {
       Uninstall-ChocolateyPackage -PackageName "$packageName" `
                                   -FileType "$installerType" `
                                   -SilentArgs "$($silentArgs)" `
                                   -File "$($_.UninstallString)" `
                                   -ValidExitCodes $validExitCodes}

ToDo (future)

Switch to parameters to hash

$packageName = '{{PackageName}}'
$softwareName= "$packageName"
$installerType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
$validExitCodes = @(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant