【问题标题】:Determining Windows OS architecture in a non locale-sensitive manner以非区域设置敏感的方式确定 Windows 操作系统架构
【发布时间】:2010-07-28 20:25:51
【问题描述】:

我正在寻找一种可靠的方法来确定 Windows 操作系统架构(32 位或 64 位),这种方法对 Windows 版本或系统区域设置/显示语言不敏感。我将使用 C# 来执行此操作。澄清一下,我需要的是操作系统架构,而不是处理器架构,也不是应用程序架构。

我知道我可以使用 IntPtr.Size,但这取决于应用程序的目标架构。

我还尝试使用 System.Management.ManagementClass 从 Win32_OperatingSystem 获取“OSArchitecture”属性。但是,此值会根据显示语言而变化。 (例如,如果我将显示语言设置为西班牙语,我会得到“64 位”,而在英语中则是“64 位”。)

谢谢!

【问题讨论】:

    标签: c# windows architecture x86-64


    【解决方案1】:

    这是How to detect Windows 64 bit platform with .net?的答案

    基本上,您可以通过首先检查进程的类型,然后调用正确的方法来进行正确的检查来做到这一点。

    【讨论】:

    • 感谢您的帮助。这可能是我最终会做的事情。
    【解决方案2】:

    安装 Windows 架构:

        string getOSArchitecture()
        {
            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)))
                return "64-bit";
            return "32-bit";
        }
    

    【讨论】:

      【解决方案3】:

      在 .NET 4.0 或更高版本上,有一个 System.Environment.Is64bitOperatingSystem 属性。

      【讨论】:

        【解决方案4】:

        对于其他有相同问题的人来说,这似乎也可以解决问题。我不确定它有多强大:

        public bool Is64Bit() { return (System.Environment.GetEnvironmentVariable("ProgramFiles(x86)") != null); }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-05
          • 1970-01-01
          • 2010-12-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多