17
8
What's the best and quickest way to detect whether you're running a 32 or 64-bit version of Windows Server from the command line?
(Cygwin is installed)
17
8
What's the best and quickest way to detect whether you're running a 32 or 64-bit version of Windows Server from the command line?
(Cygwin is installed)
12
A slightly quicker way would be to check for the existence of the %ProgramFiles(x86)% directory. If it exists then you're running 64-bit, if it doesn't exist then you're running 32-bit.
Quick one-liner:
if exist "%ProgramFiles(x86)%" echo 64-bit
That will output 64-bit
if the directory exists. That would fail, though, if it didn't exist as a variable but it did exist as a directory (as %ProgramFiles(x86)%).
You can also use the find tool to have a more accurate way to determine bitness.
set | find "ProgramFiles(x86)"
or using the systeminfo
command previously
systeminfo | find /I "System type"
(included the /I
to work across XP/2003/2008/etc)
22
How about:
echo %PROCESSOR_ARCHITECTURE%
This will return x86 on 32-bit systems and AMD64 (or IA64) on 64-bit systems.
2
THIS ANSWER HAS PROBLEMS!! - http://stackoverflow.com/questions/1738985/why-processor-architecture-always-returns-x86-instead-of-amd64
– T.Todua – 2014-09-15T10:02:39.0372How comes this had 0 votes? o.O (+1) – Apache – 2011-05-31T10:30:56.373
1This is a much better solution then checking for the existence of the Program Files (x86)
directory as someone else posted. You could also check for the existence of the %PROGRAMFILES(X86)%
environment variable (if it doesn't exist, then you're on an x86 machine). – Breakthrough – 2011-08-04T19:45:35.967
9
systeminfo
It will list quite a bit, about 10 fields down there is one called System Type. This will tell you if it's x86 or x64
8
systeminfo | find /I "System type"
This is locale dependent, and slow.
echo %PROCESSOR_ARCHITECTURE%
Notice, that it's x86 in 32-bit cmd.exe
.
Correct way:
set Arch=x64
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
if not defined PROCESSOR_ARCHITEW6432 set Arch=x86
)
The Best ANSWER! with additional validator PROCESSOR_ARCHITEW6432
– T.Todua – 2014-09-15T10:03:38.840
Completely agree on your thoughts on using 'systeminfo'. Thanks for your suggestion, I've used that in one of my scripts – abstrask – 2012-04-18T08:58:49.847
6
Other way to check with a WMI query:
PowerShell:
(gwmi win32_computersystem).SystemType
CMD:
wmic OS get OSArchitecture
Extracted from here: http://www.sysadmit.com/2015/10/windows-como-saber-si-es-de-32-o-64-bits.html
5
There are numerous ways to check the processor architecture under Windows:
The fastest, easiest, and most compatible way to check the processor architecture in at least Windows 2000 and up is to examine the PROCESSOR_ARCHITECTURE
environment variable:
echo %PROCESSOR_ARCHITECTURE%
However, this can give different results, depending on the way in which the command-prompt is opened. To avoid getting “unexpected results” due to WoW64, you can read it directly from the registry (Microsoft made no less than two typos in the key):
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE
Microsoft also suggests reading the hardware information store from the registry:
reg query "HKLM\Hardware\Description\System\CentralProcessor\0" /v Identifier
You can also check for the existence of the x86 version of the Program Files
directory (or the environment variable that points to it) since it would only exist on a 64-bit system. Unlike the PROCESSOR_ARCHITECTURE
variable, this is not dependant on the way that the command prompt is run since the directory exists (or not) regardless of how the prompt is opened:
::via env-var
if not defined ProgramFiles(x86) echo 32-bit
::via file-system
if not exist "%systemdrive%\Program Files (x86)" echo 32-bit
These methods can be combined in a single batch-file (e.g., cpuinfo.bat
) and provides a nice, lightning fast way to check the system from a standard Windows NT command-prompt without needing to resort to running other programs or frameworks.
This was tested on 32-bit and Intel 64-bit systems (please test on AMD64), giving correct results in <1 second:
@echo off
echo PROCESSOR_ARCHITECTURE var:
echo %PROCESSOR_ARCHITECTURE% | find /i "x86" > nul
if %errorlevel%==0 (
echo 32-bit
) else (
echo 64-bit
)
echo.
echo PROCESSOR_ARCHITECTURE reg:
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE | find /i "x86" > nul
if %errorlevel%==0 (
echo 32-bit
) else (
echo 64-bit
)
echo.
echo CentralProcessor reg:
reg query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > nul
if %errorlevel%==0 (
echo 32-bit
) else (
echo 64-bit
)
echo.
echo ProgramFiles(x86) var:
if not defined ProgramFiles(x86) (
echo 32-bit
) else (
echo 64-bit
)
echo.
echo ProgramFiles(x86) dir:
if not exist "%systemdrive%\Program Files (x86)" (
echo 32-bit
) else (
echo 64-bit
)
echo.
3
I really had to dig into this and have a real look around in WMI.
The best option in my opinion is to simply use this PowerShell string
(Get-WmiObject win32_ComputerSystem -ComputerName $ComputerName).SystemType
This even work with old Windows 2003 and XP
The answer will be one of
x64-based PC
Or if reverting to some old fashioned cmd tools
wmic computersystem get systemtype
2
Although this is not the ideal answer, and systeminfo.exe
should be your preferred method of determining the system type, i.e. 32-bit or 64-bit, this solution runs a little faster if you do not want to wait for systeminfo.exe
to finish its work.
The command:
reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | find "BuildLabEx"
With the correct changes to the registry query and search string you can also check for operating system versions as far back as Windows 95. systeminfo.exe
is more exact and the correct way of querying, reg.exe query
is faster and more backwards compatible.
1Rather than piping the output through Microsoft's buggy "find" command, you can have REG.EXE pull the exact value with the /v switch: reg query "HKLM\[..as before..]\Version" /v BuildLabEx
– Ti Strga – 2015-01-27T20:40:51.457
Thanks Tom for the edits, you removed important information to the answer, and then proceeded to actually introduce a bug. – Justin – 2011-04-06T20:53:53.567
0
Method 1:
(Two step Validation with PROCESSOR_ARCHITECTURE
and PROCESSOR_ARCHITEW6432
)
set Arch=x64
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
if not defined PROCESSOR_ARCHITEW6432 set Arch=x86
)
if %Arch% == "x64" (
msg * "yessss"
) else (
msg * "noooo"
)
Method 2:
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x32" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT echo "YESSS"
if %OS%==64BIT echo "NOOO"
-1
Using the WMI interface, under the Command Prompt. Open the Command Prompt as Administrator, and type wmic OS get OSArchitecture
and press Enter
it should be
systeminfo | find "System type"
Capitol T returns nothing. – Nathan DeWitt – 2009-11-10T15:56:30.017Yup, completely missed that. Thanks Nathan! Of course, you could also use the /I switch to make it case insensitive as well. – Joshua – 2009-11-10T22:55:15.973
Server 2008, its actually a capital 'T'.
Either way. Thanks for the answer - perfect. – romant – 2009-11-11T04:37:06.040
Fine! I went ahead and included the /I switch to systeminfo so that it'll find it whether it's a capital t or not! :) – Joshua – 2009-11-11T15:19:58.470