How to detect Windows 64-bit platform with .NET?

前端 未结 29 3257
野性不改
野性不改 2020-11-22 04:53

In a .NET 2.0 C# application I use the following code to detect the operating system platform:

string os_platform = System.Environment.OSVersion.Platform.ToS         


        
29条回答
  •  梦如初夏
    2020-11-22 05:33

    I found this to be the best way to check for the platform of the system and the process:

    bool 64BitSystem = Environment.Is64BitOperatingSystem;
    bool 64BitProcess = Environment.Is64BitProcess;
    

    The first property returns true for 64-bit system, and false for 32-bit. The second property returns true for 64-bit process, and false for 32-bit.

    The need for these two properties is because you can run 32-bit processes on 64-bit system, so you will need to check for both the system and the process.

提交回复
热议问题