问题
I'm trying to write a batch script to execute a certain program depending on the architecture of the system. For example, something like this:
If ProcessorArch=64-bit 7zip64.exe
If ProcessorArch=32-bit 7zip.exe
If ProcessorArch=x86-64-bit 7zipx86-64.exe
Thank you
回答1:
The value of environment variable PROCESSOR_ARCHITECTURE
is
always x86 on running 32-bit Windows independent on architecture of the CPU as even on a motherboard with an Intel/AMD x64 processor a 32-bit Windows can be installed and running instead of Windows x64.
is either x86 or AMD64 or IA64 on running 64-bit Windows depending on
- architecture of CPU and running Windows: AMD64 or IA64
- architecture of currently running process: AMD64 or IA64 or x86
See the Microsoft MSDN articles:- WOW64 Implementation Details
- File System Redirector
- Registry Keys Affected by WOW64 (Windows)
On using a batch file to install something it is in general advisable to take the architecture of the Windows operating system into account and not the architecture of the command process executing currently the batch file.
On running a batch file which just calls other applications it is usually advisable to run the application with same architecture as the current process uses which is the reason why value of environment variable PROCESSOR_ARCHITECTURE
depends on 64-bit Windows also on architecture of current process.
7-Zip for Windows is available either as x86 or as x64 application. There is no "x86-64" version as far as I know.
A batch code which could be used is:
if /I "%PROCESSOR_ARCHITECTURE%" == "x86" goto Zip32
if /I "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto Zip64
echo ERROR: Processor architecture %PROCESSOR_ARCHITECTURE% is not supported.
echo/
pause
goto :EOF
:Zip32
if "%ProgramFiles(x86)%" == "" (
echo Using 32-bit 7-Zip ...
) else (
echo Using 32-bit 7-Zip on 64-bit Windows ...
)
rem The commands using 32-bit 7-Zip.
goto :EOF
:Zip64
echo Using 64-bit 7-Zip ...
rem The commands using 64-bit 7-Zip.
来源:https://stackoverflow.com/questions/42044600/if-processor-xx-bit-do-this-in-batch