Skip to content

Commit f9a25e7

Browse files
committed
fix: detect native Windows architecture under x64 emulation
An x64-emulated PowerShell on Windows ARM64 reports OSArchitecture=X64 and would install the x64 build. Read the machine architecture from the Session Manager registry key (with env-var fallback), which reports the hardware architecture regardless of process emulation.
1 parent 5da2e54 commit f9a25e7

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

apps/pythinker-web/public/install.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,23 @@ if ([System.Environment]::OSVersion.Platform -ne [System.PlatformID]::Win32NT) {
455455
if (-not $Version) { $Version = Get-LatestVersion }
456456
$Version = $Version.TrimStart('v')
457457

458-
$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
459-
$archLabel = switch ($architecture) {
460-
([System.Runtime.InteropServices.Architecture]::Arm64) { 'arm64' }
461-
([System.Runtime.InteropServices.Architecture]::X64) { 'x64' }
462-
default { Fail "unsupported Windows architecture: $architecture (need x64 or arm64)" }
458+
# The machine's native architecture, independent of process emulation: an
459+
# x64-emulated PowerShell on Windows ARM64 reports OSArchitecture=X64, but the
460+
# registry value below always holds the real hardware architecture.
461+
function Get-NativeArchitecture {
462+
try {
463+
$reg = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -ErrorAction Stop
464+
if ($reg.PROCESSOR_ARCHITECTURE) { return [string]$reg.PROCESSOR_ARCHITECTURE }
465+
} catch {}
466+
if ($env:PROCESSOR_ARCHITEW6432) { return $env:PROCESSOR_ARCHITEW6432 }
467+
return [string]$env:PROCESSOR_ARCHITECTURE
468+
}
469+
470+
$nativeArchitecture = Get-NativeArchitecture
471+
$archLabel = switch ($nativeArchitecture) {
472+
'ARM64' { 'arm64' }
473+
'AMD64' { 'x64' }
474+
default { Fail "unsupported Windows architecture: $nativeArchitecture (need x64 or arm64)" }
463475
}
464476
$target = "win32-$archLabel"
465477

0 commit comments

Comments
 (0)