2011-09-16 202 views
0

可能重复:
How to detect Windows 64 bit platform with .net?Environment.GetEnvironmentVariable检查操作系统版本32位/ 64位

项目:C#0.5

描述:代码检查是否底层机器是64位或32位操作系统。 返回值:该代码始终返回null值。 为什么?因为它是返回变量未设置

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

有什么理由,为什么你不能使用'Environment.Is64BitOperatingSystem'或'Environment.Is64BitProcess' ? – LukeH

+0

问题重复 –

回答

1

的代码返回null。检查,如果你是在64位环境较好的方法是调用Environment.Is64BitOperatingSystem和Environment.Is64BitProcess

0
if (Environment.Is64BitOperatingSystem) 
{ 
    return Environment.GetEnvironmentVariable("SysWOW64"); 
} 
else 
{ 
    return Environment.GetEnvironmentVariable("system32");  
} 
相关问题