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
This commit is contained in:
Alexander A. Klimov 2024-07-04 15:03:52 +02:00
parent 15b464f78c
commit e08f785608
2 changed files with 5 additions and 5 deletions

View file

@ -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;

View file

@ -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;