Detect whether current Windows version is 32 bit or 64 bit

前端 未结 23 2408
抹茶落季
抹茶落季 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:19

    In C#:

    public bool Is64bit() {
        return Marshal.SizeOf(typeof(IntPtr)) == 8;
    }
    

    In VB.NET:

    Public Function Is64bit() As Boolean
       If Marshal.SizeOf(GetType(IntPtr)) = 8 Then Return True
       Return False
    End Function
    
    0 讨论(0)
  • 2020-11-28 04:19

    I use this:

    @echo off
    if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
     echo 64 BIT
    ) else (
     echo 32 BIT
    )
    

    It works on Windows XP, tested it on Windows XP Professional Both 64 bit and 32 bit.

    0 讨论(0)
  • 2020-11-28 04:19

    Here is a simpler method for batch scripts

        @echo off
    
        goto %PROCESSOR_ARCHITECTURE%
    
        :AMD64
        echo AMD64
        goto :EOF
    
        :x86 
        echo x86
        goto :EOF
    
    0 讨论(0)
  • 2020-11-28 04:20

    From a batch script:

    IF PROCESSOR_ARCHITECTURE == x86 AND
       PROCESSOR_ARCHITEW6432 NOT DEFINED THEN
       // OS is 32bit
    ELSE
       // OS is 64bit
    END IF
    

    Using Windows API:

    if (GetSystemWow64Directory(Directory, MaxDirectory) > 0) 
       // OS is 64bit
    else
       // OS is 32bit
    

    Sources:

    1. HOWTO: Detect Process Bitness
    2. GetSystemWow64Directory function
    0 讨论(0)
  • 2020-11-28 04:20

    I used this within a login script to detect 64 bit Windows

    if "%ProgramW6432%" == "%ProgramFiles%" goto is64flag

    0 讨论(0)
  • 2020-11-28 04:20

    I tested the following batch file on Windows 7 x64/x86 and Windows XP x86 and it's fine, but I haven't tried Windows XP x64 yet, but this will probably work:

    If Defined ProgramW6432 (Do x64 stuff or end if you are aiming for x86) else (Do x86 stuff or end if you are aiming for x64) 
    
    0 讨论(0)
提交回复
热议问题