Detecting 64 bit vs 32 bit Windows

Before starting to look at this, its important to be clear about what you mean by "64 bit". You can have a 64 bit CPU, a 64 bit operating system and a 64 bit process running. It is equally possible to have 64 bit CPU, a 32 bit operating system installed and a 16 bit process running.

The table below shows a few of the combinations you may need to account for:

  CPU Hardware Operating System Process
Windows 3.1 16 16 16
Windows 95/NT 32 32 32
Windows XP (16 bit compatibility) 32 32 16
Windows XP 32 32 32
Windows XP on new hardware 64 32 32
Windows 7/2008 on old hardware 32 32 32
Windows 7/2008 (32 bit compatibility) 64 64 32 (WOW)
Windows 7/2008 64 64 64

Detect 64 bit processor hardware

In Vista and greater, you can use wmic os get osarchitecture, or in WMI Win32_ComputerSystem/OSArchitecture sadly this is not supported in XP or 2003
There are a number of promising looking options in WMI and Systeminfo, but they all pertain to the OS not the CPU.

Detect a 64 bit Operating System

:: Installed OS
Set _Bitness=64
IF %PROCESSOR_ARCHITECTURE% == x86 (
  IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set _Bitness=32
  )
Echo Operating System is %_Bitness% bit

Via David Wang’s blog post: Detect OS Bitness

Detect a 64 bit Process

On Windows 7, running C:\windows\SysWOW64\cmd.exe will launch a 32 bit instance of CMD.exe even if the OS is 64 bit. Applications that are compiled for a 32 bit processor will run in a similar way. We can detect this with the %PROCESSOR_ARCHITECTURE% environment variable.

:: Process
If %PROCESSOR_ARCHITECTURE% == x86 (
   Set _ps_bitness=32
   ) ELSE ( Set _ps_bitness=64)
Echo Process is %_ps_bitness% Bit

Program Files location for 32 bit applications

:: Program Files location for 32 bit apps
If DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles(x86)%
If Not DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles%
Echo Program Files location for 32 bit apps:
Echo %_programs%

Program Files location for 64 bit applications

:: Program Files location for 64 bit apps
Echo %ProgramFiles%

“It's not so much that we're afraid of change or so in love with the old ways, but it's that place in between that we fear... it's like being between trapezes” ~ Marilyn Ferguson

Related:

Q556009 - How to check if a computer is running a 32 bit or 64 bit Operating System.


© Copyright SS64.com 1999-2014
Some rights reserved