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:
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)
Is there a way to do this?
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.