Skip to content

Commit ae7e50b

Browse files
authored
Test registry path before invoking Get-ChildItem (actions#95)
1 parent 7d36f50 commit ae7e50b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

installers/win-setup-template.ps1

+10-6
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ function Remove-RegistryEntries {
2828
$versionFilter = Get-RegistryVersionFilter -Architecture $Architecture -MajorVersion $MajorVersion -MinorVersion $MinorVersion
2929

3030
$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
31-
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
32-
foreach ($key in $regKeys) {
33-
if ($key.getValue("DisplayName") -match $versionFilter) {
34-
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
31+
if (Test-Path -Path Registry::$regPath) {
32+
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
33+
foreach ($key in $regKeys) {
34+
if ($key.getValue("DisplayName") -match $versionFilter) {
35+
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
36+
}
3537
}
3638
}
3739

3840
$regPath = "HKEY_CLASSES_ROOT\Installer\Products"
39-
Get-ChildItem -Path Registry::$regPath | Where-Object { $_.GetValue("ProductName") -match $versionFilter } | ForEach-Object {
40-
Remove-Item Registry::$_ -Recurse -Force -Verbose
41+
if (Test-Path -Path Registry::$regPath) {
42+
Get-ChildItem -Path Registry::$regPath | Where-Object { $_.GetValue("ProductName") -match $versionFilter } | ForEach-Object {
43+
Remove-Item Registry::$_ -Recurse -Force -Verbose
44+
}
4145
}
4246

4347
$uninstallRegistrySections = @(

0 commit comments

Comments
 (0)