From e08f78560874fbe52e025a759a5055499a43884c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 4 Jul 2024 15:03:52 +0200 Subject: [PATCH] Properly detect OS arch (not current shell arch) [IntPtr]::Size depends on the PS exe arch, but there's also an x86 one on x64. But Env:ProgramFiles(x86) is always defined on an x64 OS. https://stackoverflow.com/a/61396489 --- .../icingaagent/getters/Get-IcingaAgentInstallation.psm1 | 8 ++++---- lib/core/repository/Get-IcingaRepositoryPackage.psm1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentInstallation.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentInstallation.psm1 index dad4888c..5a02599e 100644 --- a/lib/core/icingaagent/getters/Get-IcingaAgentInstallation.psm1 +++ b/lib/core/icingaagent/getters/Get-IcingaAgentInstallation.psm1 @@ -1,12 +1,12 @@ function Get-IcingaAgentInstallation() { [string]$architecture = ''; - if ([IntPtr]::Size -eq 4) { - $architecture = "x86"; - $regPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'; - } else { + if (Test-Path 'Env:ProgramFiles(x86)') { $architecture = "x86_64"; $regPath = @('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'); + } else { + $architecture = "x86"; + $regPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'; } $RegistryData = Get-ItemProperty $regPath; diff --git a/lib/core/repository/Get-IcingaRepositoryPackage.psm1 b/lib/core/repository/Get-IcingaRepositoryPackage.psm1 index 5e7fc898..623dc98c 100644 --- a/lib/core/repository/Get-IcingaRepositoryPackage.psm1 +++ b/lib/core/repository/Get-IcingaRepositoryPackage.psm1 @@ -33,7 +33,7 @@ function Get-IcingaRepositoryPackage() $SourceRepo = $null; $RepoName = $null; [bool]$HasRepo = $FALSE; - [bool]$Isx86 = [bool]([IntPtr]::Size -eq 4); + [bool]$Isx86 = [bool](-not (Test-Path 'Env:ProgramFiles(x86)')); foreach ($entry in $Repositories) { $RepoContent = Read-IcingaRepositoryFile -Name $entry.Name;