windows C# 如何获得操作系统架构(x86 或 x64)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3639129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# How do you get the operating system architecture (x86 or x64)?
提问by xZerox
Possible Duplicate:
How to detect Windows 64 bit platform with .net?
How can I retrieve the operating system architecture (x86 or x64) with .NET 2.0?
如何使用 .NET 2.0 检索操作系统架构(x86 或 x64)?
I have not found any good method to get the OS architecture on Google. What I found was how to tell whether the process is 32-bit or 64-bit.
我还没有找到任何在 Google 上获取操作系统架构的好方法。我发现的是如何判断进程是 32 位还是 64 位。
If there isn't anyway to find out in .NET 2.0 please tell me. :)
如果无论如何都无法在 .NET 2.0 中找到,请告诉我。:)
回答by djdd87
Not the accepted answer in the duplicate question, but this is how I'd do it:
不是重复问题中接受的答案,但这就是我的做法:
Use GetEnvironmentVariable
to look for the PROCESSOR_ARCHITEW6432 variable. If it doesn't exist, you must be running 32bit:
使用GetEnvironmentVariable
去寻找PROCESSOR_ARCHITEW6432变量。如果它不存在,则您必须运行 32 位:
bool is64bit = !string.IsNullOrEmpty(
Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));