Search code examples
windowspowershellarmcompatibility

Is there a programmatic way to determine which application processor architectures are supported?


I'm writing a set of PowerShell functions that could theoretically be running in an x86, AMD64, ARM, or ARM64 PowerShell process. The script function will launch a specified executable, but first I'd like to check if the executable's "machine type" is actually supported by the current Windows installation.

Examples:

  • Windows Server 2019 can have its WOW64 compatibility layer removed - I'd like to detect that WOW64 is unavailable before attempting to launch an x86 EXE
  • Windows 10 on ARM64 supports x86, ARM, and ARM64 executables at the time of writing, but Microsoft is reportedly working on AMD64 (x64) application support through an extension of the WOW subsystem. So, in some future release of Windows, Windows 10 on ARM64 will support AMD64 applications.

Rather than hardcoding a bunch of checks, is there a way to determine whether the native OS or its WOW subsystem can run a given executable?

Ignoring the specifics of the PowerShell language and using pseudocode, the ideal function would be something like:


IsProcessorArchitectureAvailable(strProcessorArchitecture)

  • strProcessorArchitecture would be "x86", "AMD64", "ARM", or "ARM64"
  • The function would return True if applications that use the specified processor architecture can run, False otherwise.

Is there a way to do this?


Solution

  • The IsWow64GuestMachineSupported API can be used to determine if WOW64 is turned off or not:

    Apps that need to determine if WOW64 is turned off or not. For example, many apps assume x86-64 systems can always execute x86-32 code at all times, everywhere. Note that this ability does not exist on WinPE or Xbox, and it is an optional component in Server.

    Using this API you can also check for ARM architectures, see Image File Machine Constants.

    There is also IsWow64Process2 which returns the native architecture of the host system.

    To call these API's you would need to P/Invoke with C# from PowerShell.

    Full C# Example can be found here and PowerShell example here.