gpt4 book ai didi

c# - 检测cpu架构的正确方法?

转载 作者:行者123 更新时间:2023-11-30 12:18:32 26 4
gpt4 key购买 nike

我正在尝试检测用于安装 x86 msi 或 x64 msi 文件的正确 cpu 架构。

如果我是对的,对于 msi,我需要 os cpu 架构

我不能完全确定我的方法是否正确,因为我无法对其进行测试。你怎么看?

private static string GetOSArchitecture()
{
string arch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
string archWOW = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
if(archWOW != null && archWOW != "" && archWOW.Contains("64"))
return "x64";
if(arch.Contains("86"))
return "x86";
if (arch.Contains("64"))
return "x64";
return "";
}

最佳答案

您可以 P/Invoke 到 GetNativeSystemInfo ,这将给出操作系统的 CPU 架构,即使是在 64 位操作系统上的 32 位进程中也是如此。

关于c# - 检测cpu架构的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2017409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com