Detect whether current Windows version is 32 bit or 64 bit

前端 未结 23 2871
抹茶落季
抹茶落季 2020-11-28 03:47

Believe it or not, my installer is so old that it doesn\'t have an option to detect the 64-bit version of Windows.

Is there a Windows DLL call or (even better) an en

23条回答
  •  余生分开走
    2020-11-28 04:24

    Another way created by eGerman that uses PE numbers of compiled executables (does not rely on registry records or environment variables):

    @echo off &setlocal
    
    
    call :getPETarget "%SystemRoot%\explorer.exe"
    
    
    if "%=ExitCode%" EQU "00008664" (
        echo x64
    ) else (
        if "%=ExitCode%" EQU "0000014C" (
            echo x32
        ) else (
            echo undefined
        )
    )
    
    
    goto :eof
    
    
    :getPETarget FilePath
    :: ~~~~~~~~~~~~~~~~~~~~~~
    :: Errorlevel
    ::   0 Success
    ::   1 File Not Found
    ::   2 Wrong Magic Number
    ::   3 Out Of Scope
    ::   4 No PE File
    :: ~~~~~~~~~~~~~~~~~~~~~~
    :: =ExitCode
    ::   CPU identifier
    
    setlocal DisableDelayedExpansion
    set "File=%~1"
    set Cmp="%temp%\%random%.%random%.1KB"
    set Dmp="%temp%\%random%.%random%.dmp"
    
    REM write 1024 times 'A' into a temporary file
    if exist "%File%" (
      >%Cmp% (
        for /l %%i in (1 1 32) do !Dmp! (
      for /f "skip=1 tokens=1,2 delims=: " %%i in ('fc /b "!File!" !Cmp!^|findstr /vbi "FC:"') do (
        set /a "Y=0x%%i"
        for /l %%k in (!X! 1 !Y!) do echo 41
        set /a "X=Y+2"
        echo %%j
      )
    )
    del !Cmp!
    
    REM read certain values out of the HEX dump
    set "err="
    

提交回复
热议问题