How to Get Processor Architecture (x86, x64, ARM) in a Batch Script
Knowing the processor architecture is a critical pre-flight check for many scripts, especially those that deal with software installation. A script must know whether the operating system is 32-bit (x86), 64-bit (x64/AMD64), or ARM64 to download and run the correct version of an application. Running a 64-bit program on a 32-bit OS will fail, so a robust script must verify the architecture first.
This guide will teach you how to reliably determine the processor and operating system architecture using a built-in, standard environment variable. This is the simplest and most direct method, and we will also cover the more detailed WMIC command for comparison.
The Core Method: The %PROCESSOR_ARCHITECTURE% Variable
The simplest, fastest, and most reliable way to determine the architecture is by using the built-in %PROCESSOR_ARCHITECTURE% environment variable. This variable is set by the operating system during startup and is always available in any command prompt session.
This variable tells you the native architecture of the operating system currently running.
Basic Example: Displaying the System Architecture
This simple script shows the value of the environment variable.
@ECHO OFF
ECHO --- Checking Processor Architecture ---
ECHO.
ECHO The system architecture is: %PROCESSOR_ARCHITECTURE%
Output (on a typical 64-bit PC)
--- Checking Processor Architecture ---
The system architecture is: AMD64
Understanding the Possible Values
The %PROCESSOR_ARCHITECTURE% variable will typically return one of three values on modern systems:
| Value | Meaning | Description |
|---|---|---|
AMD64 | 64-bit x86 | This is the standard value for nearly all modern 64-bit Windows PCs, regardless of whether the CPU is from Intel or AMD. |
x86 | 32-bit x86 | This indicates a 32-bit operating system. It could also appear if you are in a 32-bit cmd.exe process on a 64-bit OS. |
ARM64 | 64-bit ARM | This is for devices like the Microsoft Surface Pro X that run Windows on an ARM-based processor. |
For most software installation scripts, the primary check is to see if the value is AMD64.
An Alternative Method: Using WMIC
The WMIC utility can also provide this information, often with more detail. The OS alias has a specific property for this.
Command: WMIC OS GET OSArchitecture /VALUE
@ECHO OFF
ECHO --- Getting OS Architecture from WMIC ---
ECHO.
WMIC OS GET OSArchitecture
Output (on a 64-bit PC)
OSArchitecture
64-bit
While WMIC works perfectly, using the %PROCESSOR_ARCHITECTURE% environment variable is much faster and more direct, as it doesn't require launching an external program.
Common Pitfalls and How to Solve Them
-
WoW64 Redirection: This is the most important concept to understand. On a 64-bit OS, if you are running a 32-bit process (like the
cmd.exefromC:\Windows\SysWOW64), the%PROCESSOR_ARCHITECTURE%variable will reportx86, even though the OS is 64-bit. This is by design, to let the 32-bit process know its own context.- Solution: To find the true native OS architecture, you must check a different variable:
%PROCESSOR_ARCHITEW6432%. This variable only exists inside a 32-bit process running on a 64-bit system.
IF DEFINED PROCESSOR_ARCHITEW6432 (
ECHO This is a 32-bit process on a 64-bit OS.
ECHO The true OS architecture is: %PROCESSOR_ARCHITEW6432%
) ELSE (
ECHO This is a native process.
ECHO The OS architecture is: %PROCESSOR_ARCHITECTURE%
) - Solution: To find the true native OS architecture, you must check a different variable:
-
Case Sensitivity: When you check the value of the variable, it's a good practice to use a case-insensitive comparison (
/I) in yourIFstatement.IF /I "%PROCESSOR_ARCHITECTURE%"=="AMD64" (ECHO This is a 64-bit OS.)
Practical Example: A "Smart Installer" Script
This script needs to download the correct version of a tool (either 32-bit or 64-bit) based on the operating system's architecture. It uses the robust check that accounts for WoW64.
@ECHO OFF
SETLOCAL
SET "Arch="
REM --- Robustly determine the true OS architecture ---
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" SET "Arch=x64"
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
IF DEFINED PROCESSOR_ARCHITEW6432 (
SET "Arch=x64"
) ELSE (
SET "Arch=x86"
)
)
ECHO --- Smart Application Downloader ---
ECHO.
ECHO Detected system architecture: %Arch%
ECHO.
IF "%Arch%"=="x64" (
ECHO Downloading the 64-bit version of the application...
REM (Download command for 64-bit installer would go here)
) ELSE (
ECHO Downloading the 32-bit version of the application...
REM (Download command for 32-bit installer would go here)
)
ENDLOCAL
Conclusion
Getting the processor architecture is a simple but essential task for writing adaptable and error-proof installation scripts.
- The
%PROCESSOR_ARCHITECTURE%environment variable is the fastest and most direct method. - Be aware that this variable reflects the architecture of the current
cmd.exeprocess, which can bex86on a 64-bit OS (due to WoW64). - For the most robust check, you must also check for the existence of the
%PROCESSOR_ARCHITEW6432%variable to correctly identify the underlying OS architecture. - The
WMIC OS GET OSArchitecturecommand is a reliable alternative, though it is slightly slower.