Detect whether current Windows version is 32 bit or 64 bit

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

    A lot of answers mention calling IsWoW64Process() or related functions. This is not the correct way. You should use GetNativeSystemInfo() which was designed for this purpose. Here's an example:

    SYSTEM_INFO info;
    GetNativeSystemInfo(&info);
    
    if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
      // It's a 64-bit OS
    }
    

    Also see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724340%28v=vs.85%29.aspx

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

    Using Windows Powershell, if the following expression returns true, then it's a 64 bit OS:

    (([Array](Get-WmiObject -Class Win32_Processor | Select-Object AddressWidth))[0].AddressWidth -eq 64)

    This was taken and modified from: http://depsharee.blogspot.com/2011/06/how-do-detect-operating-system.html (Method #3). I've tested this on Win7 64 bit (in both 32 and 64 bit PowerShell sessions), and XP 32 bit.

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

    Interestingly, if I use

    get-wmiobject -class Win32_Environment -filter "Name='PROCESSOR_ARCHITECTURE'"
    

    I get AMD64 in both 32-bit and 64-bit ISE (on Win7 64-bit).

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

    I know this is ancient but, here's what I use to detect Win764

    On Error Resume Next
    
    Set objWSHShell = CreateObject("WScript.Shell")
    
    strWinVer = objWSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx")
    
    If len(strWinVer) > 0 Then
        arrWinVer = Split(strWinVer,".")
        strWinVer = arrWinVer(2)
    End If
    
    Select Case strWinVer
    Case "x86fre"
    strWinVer = "Win7"
    Case "amd64fre"
        strWinVer = "Win7 64-bit"
    Case Else
        objWSHShell.Popup("OS Not Recognized")
        WScript.Quit
    End Select
    
    0 讨论(0)
  • 2020-11-28 04:38

    I want to add what I use in shell scripts (but can easily be used in any language) here. The reason is, that some of the solutions here don't work an WoW64, some use things not really meant for that (checking if there is a *(x86) folder) or don't work in cmd scripts. I feel, this is the "proper" way to do it, and should be safe even in future versions of Windows.

     @echo off
     if /i %processor_architecture%==AMD64 GOTO AMD64
     if /i %PROCESSOR_ARCHITEW6432%==AMD64 GOTO AMD64
        rem only defined in WoW64 processes
     if /i %processor_architecture%==x86 GOTO x86
     GOTO ERR
     :AMD64
        rem do amd64 stuff
     GOTO EXEC
     :x86
        rem do x86 stuff
     GOTO EXEC
     :EXEC
        rem do arch independent stuff
     GOTO END
     :ERR
        rem I feel there should always be a proper error-path!
        @echo Unsupported architecture!
        pause
     :END
    
    0 讨论(0)
  • 2020-11-28 04:39

    I tested the solution I suggested in my question:

    Tested for Windows Environment Variable: ProgramW6432

    If it's non empty then it's 64 bit Windows.W

    0 讨论(0)
提交回复
热议问题