windows 为什么 %processor_architecture% 总是返回 x86 而不是 AMD64

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1738985/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:54:40  来源:igfitidea点击:

Why %processor_architecture% always returns x86 instead of AMD64

windowscommand-linebatch-file

提问by alice7

I am trying to retrieve the environment variable to detect whether the system is 32 or 64 bit. But on 64 bit server the environment variable %processor_architecture%is returning x86instead of AMD64.

我正在尝试检索环境变量以检测系统是 32 位还是 64 位。但是在 64 位服务器上,环境变量%processor_architecture%返回x86而不是AMD64.

Does anyone has any clue about this?

有没有人对此有任何线索?

回答by Gerald

You may be getting the wrong environment variable. If your application is a 32-bit application running on a 64-bit OS the process version of this environment variable will return x86. If you want to find the architecture of the machine, you can grab it from the following registry entry:

您可能获得了错误的环境变量。如果您的应用程序是在 64 位操作系统上运行的 32 位应用程序,则此环境变量的进程版本将返回 x86。如果要查找机器的架构,可以从以下注册表项中获取:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE

Or if you're using .NET, then you can use this call to get it:

或者,如果您使用的是 .NET,那么您可以使用此调用来获取它:

string arch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", 
    EnvironmentVariableTarget.Machine);

From the command line you can try this:

从命令行你可以试试这个:

reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE

There is even a more simple solution using cmd:

还有一个更简单的解决方案,使用cmd

ECHO %PROCESSOR_ARCHITECTURE%

回答by Patrick Cuff

You can also get this from an environment variable, PROCESSOR_ARCHITEW6432. See thisarticle for more info.

您也可以从环境变量PROCESSOR_ARCHITEW6432. 有关更多信息,请参阅这篇文章。

回答by bobince

Are you actually running a 64-bit version of Windows? If you are running 32-bit Windows on a 64-bit-capable CPU, you will still get x86.

您实际上运行的是 64 位版本的 Windows 吗?如果您在支持 64 位的 CPU 上运行 32 位 Windows,您仍将获得x86.

回答by SkyRaT

Assuming 64bit PC with 64bit Windows installation.

假设 64 位 PC 安装了 64 位 Windows。

%processor_architecture%returns x86only when getting the value in 32bit programs. In 64bit programs it returns correctly AMD64.

%processor_architecture%仅在 32 位程序中获取值时才返回x86。在 64 位程序中,它正确返回AMD64

Example: execute echo %processor_architecture%from:

示例:执行echo %processor_architecture%自:

  • 32bit Total Commander
  • 64bit Explorer
  • 32位总指挥官
  • 64位资源管理器

回答by T.Todua

MOST RELIABLE SOLUTION:

最可靠的解决方案:

Method 1:
(Two step Validation with PROCESSOR_ARCHITECTUREand PROCESSOR_ARCHITEW6432)

方法1:
(两个步骤的验证用PROCESSOR_ARCHITECTUREPROCESSOR_ARCHITEW6432

set Arch=x64
if "%PROCESSOR_ARCHITECTURE%" == "x86" ( 
    if not defined PROCESSOR_ARCHITEW6432 set Arch=x86
) 

if "%Arch%" == "x64"    (
    msg * "yessss"
) else  (
    msg * "noooo"
)

Method 2:

方法二:

reg Query "HKLM\Hardware\Description\System\CentralProcessor
$env:PROCESSOR_ARCHITECTURE
" | find /i "x32" > NUL && set OS=32BIT || set OS=64BIT if %OS%==32BIT echo "YESSS" if %OS%==64BIT echo "NOOO"

source: https://superuser.com/a/293143/249349

来源:https: //superuser.com/a/293143/249349

回答by Dan McGrath

AMD64 is a brand of CPU which is based on the x86architecture. x86-64more precisely, which is the 64-bit extension of x86.

AMD64是基于x86架构的CPU品牌。x86-64更准确地说,它是 x86 的 64 位扩展。

Thisalso relates to bobince's answer.

也与 bobince 的回答有关。

This Knowledge Base articleshows you how to determine if your system is 32-bit or 64-bit

这篇知识库文章向您展示了如何确定您的系统是 32 位还是 64 位

回答by John Thomas

I think part of the reason it is like this way is that the x86-64 architecture has to allow 32-bit programs to treat it as identical (as far as possible) to a 32-bit environment and make sure that 32-bit programs do not think it is 64-bit only (like the Itanium architecture).

我认为这种方式的部分原因是 x86-64 架构必须允许 32 位程序将其视为(尽可能)与 32 位环境相同,并确保 32 位程序不要认为它只是 64 位的(如 Itanium 架构)。

This however makes it very frustrating to people who need to access the differences between the x86-64 architecture vs 32 bit architecture on Windows.

然而,这让需要了解 Windows 上 x86-64 架构与 32 位架构之间差异的人感到非常沮丧。

回答by Eddie B

Apologize for the grave dig. However, the processor architecture environmental variable is accessible via powershell ...

为挖坟道歉。但是,处理器架构环境变量可通过 powershell 访问...

msgbox wscript.createobject("wscript.shell").environment("system").item("processor_architecture") ' always "AMD64"

msgbox wscript.createobject("wscript.shell").environment("process").item("processor_architecture") ' "AMD64" if launched via System32, "x86" if launched via SysWOW64

回答by omegastripes

I found on my Win7HB x64 system:

我在我的 Win7HB x64 系统上发现:

##代码##