如何使用 windows 批处理脚本识别 OS 是 64 位还是 32 位?
How can I identify if an OS is 64 bit or 32 bit with a windows batch script?
TL;DR : I need a piece of code that can identify the "bit" of windows and puts it in a variable called "bit", without any user input.
目前,我正在使用:
set /P choice=32 bit system? [Y/N]
if /I "%choice%" EQU "Y" (
:: 32 bit code
) else (
:: 64 bit code
)
但是,我想要一些东西来识别用户是否使用 32/64 位系统,无论他们是 运行 正在使用 32/64 位命令提示符还是那里的计算机。在 post here 中,答案仅说明了如果您 运行 正确的 CMD 位版本如何做到这一点。
Compo,网站上的一位用户,过去曾帮助我识别用户使用的 windows 版本 运行ning,这大大减少了用户输入的次数;但是,我仍然没有为 windows 的 "bit" 找到一个干净的解决方案。
怎么样:
if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
rem 32 bit
) else (
rem 64 bit
)
如果有人在 64 位系统上 运行 32 位命令提示符(它将被识别为 32 位,即使 OS 是 64 位),这会有点复杂,但是可以使用以下方式修复:
if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
if "%PROCESSOR_ARCHITEW6432%" EQU "AMD64" (
rem 64 bit OS, but running a 32 bit command prompt
) else (
rem 32 bit OS
)
) else (
rem 64 bit OS
)
TL;DR : I need a piece of code that can identify the "bit" of windows and puts it in a variable called "bit", without any user input.
目前,我正在使用:
set /P choice=32 bit system? [Y/N]
if /I "%choice%" EQU "Y" (
:: 32 bit code
) else (
:: 64 bit code
)
但是,我想要一些东西来识别用户是否使用 32/64 位系统,无论他们是 运行 正在使用 32/64 位命令提示符还是那里的计算机。在 post here 中,答案仅说明了如果您 运行 正确的 CMD 位版本如何做到这一点。
Compo,网站上的一位用户,过去曾帮助我识别用户使用的 windows 版本 运行ning,这大大减少了用户输入的次数;但是,我仍然没有为 windows 的 "bit" 找到一个干净的解决方案。
怎么样:
if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
rem 32 bit
) else (
rem 64 bit
)
如果有人在 64 位系统上 运行 32 位命令提示符(它将被识别为 32 位,即使 OS 是 64 位),这会有点复杂,但是可以使用以下方式修复:
if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
if "%PROCESSOR_ARCHITEW6432%" EQU "AMD64" (
rem 64 bit OS, but running a 32 bit command prompt
) else (
rem 32 bit OS
)
) else (
rem 64 bit OS
)