Skip to content

Foreign uninstall registry keys can cause errors in Get-IcingaAgentInstallation #833

@Donien

Description

@Donien

Problem

Icinga for Windows uses registry keys for its uninstallation (Icinga agent).

To determine what to uninstall, registry keys under HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* (and HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*) are searched.
Each key found tests for the DisplayName -eq 'Icinga 2'.

Since any program can write keys into this registry path, they can actually cause problems.
I've just had the problem that one program added its key but had no DisplayName attribute.

When comparing DisplayName this portion of the code simply fails/crashes, i.e. Get-IcingaAgentInstallation always fails.

Simplified: Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' fails

Proposed solution

Before testing DisplayName -eq 'Icinga 2' the code should also test if the attribute DisplayName exists for the given registry key in the first place.

Related part of the code:

[string]$architecture = '';
if ([IntPtr]::Size -eq 4) {
$architecture = "x86";
$regPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*';
} else {
$architecture = "x86_64";
$regPath = @('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*');
}
$RegistryData = Get-ItemProperty $regPath;
$IcingaData = $null;
foreach ($entry in $RegistryData) {
if ($entry.DisplayName -eq 'Icinga 2') {
$IcingaData = $entry;
break;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions