【问题标题】:Environment.GetEnvironmentVariable to check os version 32bit/64bit [duplicate]Environment.GetEnvironmentVariable 检查操作系统版本 32bit/64bit [重复]
【发布时间】:2011-09-16 10:12:28
【问题描述】:

可能重复:
How to detect Windows 64 bit platform with .net?

项目:C# .5

描述:代码检查底层机器是64位还是32位操作系统。 返回值:代码始终返回 null 值。 为什么?

  if (8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
            {
                return Environment.GetEnvironmentVariable("SysWOW64");
            }
            return Environment.GetEnvironmentVariable("system32");

【问题讨论】:

  • 有什么原因不能使用Environment.Is64BitOperatingSystemEnvironment.Is64BitProcess

标签: c# environment-variables


【解决方案1】:

代码返回 null 因为它返回的变量没有设置。检查您是否在 64 位环境中的更好方法是调用 Environment.Is64BitOperatingSystem 和 Environment.Is64BitProcess

【讨论】:

    【解决方案2】:
    if (Environment.Is64BitOperatingSystem) 
    {
        return Environment.GetEnvironmentVariable("SysWOW64"); 
    }
    else
    {
        return Environment.GetEnvironmentVariable("system32");       
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 2012-02-05
      • 2014-08-21
      • 2015-05-31
      • 1970-01-01
      相关资源
      最近更新 更多