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

前端 未结 29 3454
野性不改
野性不改 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:30

    @foobar: You are right, it is too easy ;)

    In 99% of the cases, developers with weak system administrator backgrounds ultimately fail to realize the power Microsoft has always provided for anyone to enumerate Windows.

    System administrators will always write better and simpler code when it comes to such a point.

    Nevertheless, one thing to note, build configuration must be AnyCPU for this environment variable to return the correct values on the correct systems:

    System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
    

    This will return "X86" on 32-bit Windows, and "AMD64" on 64-bit Windows.

提交回复
热议问题