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

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

    Given that the accepted answer is very complex. There are simpler ways. Mine is a variation of alexandrudicu's anaswer. Given that 64-bit windows install 32-bit applications in Program Files (x86) you can check if that folder exists, using environment variables (to make up for different localizations)

    e.g.

    private bool Is64BitSystem
    {
       get
       {
          return Directory.Exists(Environment.ExpandEnvironmentVariables(@"%PROGRAMFILES(X86)%"));
       }
    }
    

    This for me is faster and simpler. Given that I also wish to access a specific path under that folder based on OS version.

提交回复
热议问题