windows 用于检查 64 位或 32 位操作系统的批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12322308/
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
batch file to check 64bit or 32bit OS
提问by 5YrsLaterDBA
回答by Sam Spade
This is the correctway to perform the check as-per Microsoft's knowledgebase reference ( http://support.microsoft.com/kb/556009) that I have re-edited into just a single line of code.
这是按照 Microsoft 的知识库参考 ( http://support.microsoft.com/kb/556009)执行检查的正确方法,我已将其重新编辑为一行代码。
It doesn't rely on any environment variables or folder names and instead checks directly in the registry.
它不依赖于任何环境变量或文件夹名称,而是直接在注册表中进行检查。
As shown in a full batch file below it sets an environment variable OSequal to either 32BITor 64BITthat you can use as desired.
如下面的完整批处理文件所示,它将环境变量OS设置为32BIT或64BIT,您可以根据需要使用。
@echo OFF
reg Query "HKLM\Hardware\Description\System\CentralProcessor:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)
:64BIT
echo 64-bit...
GOTO END
:32BIT
echo 32-bit...
GOTO END
:END
" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT echo This is a 32bit operating system
if %OS%==64BIT echo This is a 64bit operating system
回答by Kerstin Fischer
I use either of the following:
我使用以下任一方法:
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (set bit=x64) ELSE (set bit=x86)
or I set the bit
variable, which I later use in my script to run the correct setup.
或者我设置了bit
变量,稍后我会在脚本中使用它来运行正确的设置。
:CheckOS
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set bit=x86) else (set bit=x64)
or...
或者...
echo "%PROCESSOR_ARCHITECTURE%"
Hope this helps.
希望这可以帮助。
回答by ThierryB
Seems to work if you do only these:
如果您只执行以下操作,则似乎有效:
@echo off
echo Detecting OS processor type
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT
echo 32-bit OS
\savdaldpm01\ProtectionAgents\RA.0.7558.0\i386\DPMAgentInstaller_x86 /q
goto END
:64BIT
echo 64-bit OS
\savdaldpm01\ProtectionAgents\RA.0.7558.0\amd64\DPMAgentInstaller_x64 /q
:END
"C:\Program Files\Microsoft Data Protection Manager\DPM\bin\setdpmserver.exe" -dpmservername sa
I've found these scriptwhich will do specific stuff depending of OS Architecture (x64 or x86):
我发现这些脚本将根据操作系统架构(x64 或 x86)执行特定操作:
*** Start ***
@echo off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessorwmic os get osarchitecture
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt
If %ERRORLEVEL% == 0 (
Echo "This is 32 Bit Operating system"
) ELSE (
Echo "This is 64 Bit Operating System"
)
*** End ***
Try to find a way without GOTO please...
请尝试找到一种没有 GOTO 的方法...
For people whom work with Unix systems, uname -m
will do the trick.
对于使用 Unix 系统的人来说,uname -m
会成功。
回答by Mahesh
@ECHO OFF
echo Check operating system ...
if defined PROGRAMFILES(X86) (
echo 64-bit sytem detected
) else (
echo 32-bit sytem detected
)
pause
reference http://support.microsoft.com/kb/556009
回答by Emil Re?a Enriquez
Run the below in the command prompt:
在命令提示符下运行以下命令:
Start -> Run -> Type cmd
and enter the command below in the resulting black box:
开始 -> 运行 -> 键入cmd
并在结果黑框中输入以下命令:
PROCESSOR_ARCHITECTURE=x86
回答by panako
'ProgramFiles(x86)' is an environment variable automatically defined by cmd.exe (both 32-bit and 64-bit versions) on Windows 64-bit machines only, so try this:
'ProgramFiles(x86)' 是仅在 Windows 64 位机器上由 cmd.exe(32 位和 64 位版本)自动定义的环境变量,所以试试这个:
PROCESSOR_ARCHITECTURE=AMD64
回答by Steve-o
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
Will appear on Win32, and
将出现在 Win32 上,并且
FOR /f "tokens=2 delims==" %%f IN ('wmic os get osarchitecture /value ^| find "="') DO SET "OS_ARCH=%%f"
IF "%OS_ARCH%"=="32-bit" GOTO :32bit
IF "%OS_ARCH%"=="64-bit" GOTO :64bit
ECHO OS Architecture %OS_ARCH% is not supported!
EXIT 1
:32bit
ECHO "32 bit Operating System"
GOTO :SUCCESS
:64bit
ECHO "64 bit Operating System"
GOTO :SUCCESS
:SUCCESS
EXIT 0
will appear for Win64.
将出现在 Win64 上。
If you are perversely running the 32-bit cmd.exe
process then Windows presents two environment variables:
如果您反常地运行 32 位cmd.exe
进程,那么 Windows 会提供两个环境变量:
::32/64Bit Switch
ECHO %PROCESSOR_ARCHITECTURE%|FINDSTR AMD64>NUL && SET ARCH=AMD64 || SET ARCH=x86
ECHO %ARCH%
PAUSE
回答by S_R
If you are running the script as an administrator, then the script can use the wmic command.
如果您以管理员身份运行脚本,则该脚本可以使用 wmic 命令。
(set | find "ProgramFiles(x86)" > NUL) && (echo "%ProgramFiles(x86)%" | find "x86") > NUL && set bits=64 || set bits=32
回答by zzeroo
Here's my personal favorite, a logical bomb :)
这是我个人最喜欢的,一个合乎逻辑的炸弹:)
##代码##With the AND's (&&
) and OR's (||
) this is a IF THEN ELSE
Batch Construct.
使用 AND 的 ( &&
) 和 OR 的 ( ||
) 这是一个IF THEN ELSE
批处理构造。
回答by teh_senaus
None of the answers here were working in my case (64 bit processor but 32 bit OS), so here's the solution which worked for me:
这里的所有答案都不适用于我的情况(64 位处理器但 32 位操作系统),所以这是对我有用的解决方案:
##代码##