开发者

Determining Windows OS architecture in a non locale-sensitive manner

开发者 https://www.devze.com 2023-01-09 20:32 出处:网络
I\'m looking for a reliable way to determine the Windows OS architecture (32-bit or 64-bit) in a manner that isn\'t sensitive to Windows version or the system locale/display language. I will be using

I'm looking for a reliable way to determine the Windows OS architecture (32-bit or 64-bit) in a manner that isn't sensitive to Windows version or the system locale/display language. I will be using C开发者_JS百科# to do this. To clarify, I need the OS architecture, not the processor architecture, and not the application architecture.

I know I can use IntPtr.Size, but this is dependent on the application's target architecture.

I've also tried using System.Management.ManagementClass to get the "OSArchitecture" property from Win32_OperatingSystem. However, the value of this changes depending on the display language. (For example, if I set the display language to Spanish I get "64 bits", when in English it is "64-bit".)

Thanks!


Here is an answer to How to detect Windows 64 bit platform with .net?

Basically, you can do this by first examining the type of the process and then call the proper method to do the correct check.


Getting installed Windows Architecture:

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


On .NET 4.0 or higher there is a System.Environment.Is64bitOperatingSystem property.


For anyone else who has the same question, this seems to do the trick as well. I'm not certain how robust it is:



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


0

精彩评论

暂无评论...
验证码 换一张
取 消