From a5d687f2e075eeec5bcf8fb6d4272dd4b1988555 Mon Sep 17 00:00:00 2001 From: dtgm Date: Sun, 22 May 2016 14:54:34 -0600 Subject: [PATCH] (GH-739) Fix templates to use helper in extension to retrieve registry key Templates are set to use the chocolatey-uninstall.extension helper by default. The helper includes a catch for invalid registry keys. Using the catch is a requirement as blindly enumerating will fail every time if even one invalid key exists. --- .../templates/ChocolateyUninstallTemplate.cs | 9 ++------- .../infrastructure.app/templates/NuspecTemplate.cs | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs index 3ad04a9e4d..53b7614cc0 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs @@ -54,13 +54,8 @@ public class ChocolateyUninstallTemplate } $uninstalled = $false -$local_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -$machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' -$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' - -[array]$key = Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) ` - -ErrorAction SilentlyContinue ` - | ? { $_.DisplayName -like ""$softwareName"" } +# Get-UninstallRegistryKey is provided by the chocolatey extension package ""chocolatey-uninstall.extension"" and must be included as a dependency in this package's nuspec if used. +[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName if ($key.Count -eq 1) { $key | % { diff --git a/src/chocolatey/infrastructure.app/templates/NuspecTemplate.cs b/src/chocolatey/infrastructure.app/templates/NuspecTemplate.cs index 01364e078e..1f14b4711b 100644 --- a/src/chocolatey/infrastructure.app/templates/NuspecTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/NuspecTemplate.cs @@ -80,6 +80,8 @@ public class NuspecTemplate + + -->