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)

link|improve this question

50% accept rate
feedback

5 Answers

up vote 4 down vote accepted

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)

link|improve this answer
it should be systeminfo | find "System type" Capitol T returns nothing. – Nathan DeWitt Nov 10 '09 at 15:56
Yup, completely missed that. Thanks Nathan! Of course, you could also use the /I switch to make it case insensitive as well. – Joshua Nov 10 '09 at 22:55
Server 2008, its actually a capital 'T'. Either way. Thanks for the answer - perfect. – romant Nov 11 '09 at 4:37
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 Nov 11 '09 at 15:19
feedback
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

link|improve this answer
feedback

How about:

echo %PROCESSOR_ARCHITECTURE%

This will return x86 on 32-bit systems and AMD64 (or IA64) on 64-bit systems.

link|improve this answer
1  
How comes this had 0 votes? o.O (+1) – Shiki May 31 '11 at 10:30
1  
This 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 Aug 4 '11 at 19:45
feedback

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.

link|improve this answer
Thanks Tom for the edits, you removed important information to the answer, and then proceeded to actually introduce a bug. – Justin Apr 6 '11 at 20:53
feedback
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
) 
link|improve this answer
Completely agree on your thoughts on using 'systeminfo'. Thanks for your suggestion, I've used that in one of my scripts – Rasmus Rask Apr 18 at 8:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.