Test registry path before invoking Get-ChildItem (#95)

This commit is contained in:
Ray 2021-05-25 00:26:11 -07:00 committed by GitHub
parent 7d36f506c4
commit ae7e50b370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,16 +28,20 @@ function Remove-RegistryEntries {
$versionFilter = Get-RegistryVersionFilter -Architecture $Architecture -MajorVersion $MajorVersion -MinorVersion $MinorVersion
$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
foreach ($key in $regKeys) {
if ($key.getValue("DisplayName") -match $versionFilter) {
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
if (Test-Path -Path Registry::$regPath) {
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
foreach ($key in $regKeys) {
if ($key.getValue("DisplayName") -match $versionFilter) {
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
}
}
}
$regPath = "HKEY_CLASSES_ROOT\Installer\Products"
Get-ChildItem -Path Registry::$regPath | Where-Object { $_.GetValue("ProductName") -match $versionFilter } | ForEach-Object {
Remove-Item Registry::$_ -Recurse -Force -Verbose
if (Test-Path -Path Registry::$regPath) {
Get-ChildItem -Path Registry::$regPath | Where-Object { $_.GetValue("ProductName") -match $versionFilter } | ForEach-Object {
Remove-Item Registry::$_ -Recurse -Force -Verbose
}
}
$uninstallRegistrySections = @(