如何检测我们在.NET中的ARM64版本的Windows 10下运行?

问题描述 投票:0回答:2

我创建了可以在Windows 10 x86,x64和ARM64(通过仿真器层)运行C#的.NET控制台应用程序。

我想知道如何检测应用程序在这些平台上运行。我知道如何检测x86和x64,但如何检测,该应用程序是内部ARM64运行?

这是运行到我的ARM64系统的Visual Studio的快照。你可以看到,它的检测为X86

enter image description here

c# .net arm64 windows-on-arm
2个回答
1
投票

您将能够通过使用来检测处理器架构

System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture

这将随后返回Architecure枚举:https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=netstandard-2.0


0
投票

OK,此代码的工作:

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
    );
}

(通过Calling IsWowProcess2 from C# .NET (P/Invoke)

© www.soinside.com 2019 - 2024. All rights reserved.