如果Processor = xx-bit批量执行此操作?

时间:2017-02-04 19:22:25

标签: batch-file

我正在尝试编写一个批处理脚本来执行某个程序,具体取决于系统的体系结构。例如,像这样:

If ProcessorArch=64-bit 7zip64.exe
If ProcessorArch=32-bit 7zip.exe
If ProcessorArch=x86-64-bit 7zipx86-64.exe

谢谢

1 个答案:

答案 0 :(得分:0)

环境变量PROCESSOR_ARCHITECTURE的值是

    在运行32位Windows上
  1. 始终 x86 独立于CPU架构,即使在具有Intel / AMD x64处理器的主板上也可以安装并运行32位Windows Windows x64。

  2. 在运行64位Windows时 x86 AMD64 IA64 ,具体取决于

    • CPU和运行Windows的架构: AMD64 IA64
    • 当前正在运行的流程架构: AMD64 IA64 x86


    请参阅Microsoft MSDN文章:

  3. 使用批处理文件进行安装时,通常建议考虑Windows操作系统的体系结构,而不是当前执行批处理文件的命令进程的体系结构。

    在运行只调用其他应用程序的批处理文件时,通常建议运行与当前进程使用的架构相同的应用程序,这就是为什么环境变量PROCESSOR_ARCHITECTURE的值依赖于64位Windows的原因关于当前过程的架构。

    7-Zip for Windows可用作x86或x64应用程序。没有" x86-64"据我所知,版本。

    可以使用的批次代码是:

    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.