System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture
然后将返回一个 Architecure
枚举值:https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=netstandard-2.0
好的,这段代码可以正常运行:
public static class ArchitectureInfo
{
public static bool IsArm64()
{
var handle = Process.GetCurrentProcess().Handle;
IsWow64Process2(handle, out var processMachine, out var nativeMachine);
return nativeMachine == 0xaa64;
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool IsWow64Process2(
IntPtr process,
out ushort processMachine,
out ushort nativeMachine
);
}
IsWow64Process2
时检查错误。 - David Heffernan