Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to build a batch file for Windows 7. This .bat file is just for installing an application. The issue is that I need to know if Windows 7 is 32 bits (and then run a 32 installer) or if it is a Windows 7 64 bits (then run the 64 bits installer). Which command can I use in a batch file to know if Windows 7 is 32 or 64 bits?

Thanks in advance!!!

share|improve this question
    
I swear I've seen this before... – Hello71 Aug 20 '10 at 17:26

in a 64bit environment you will have an environment variable called

ProgramFiles(x86)

in a 32bit environment you do not have that variable. so you could check with

if defined ProgramFiles(x86) (
   REM do stuff for 64bit here
) else (
   REM do stuff for 32bit here
)
share|improve this answer

If you don't want to use a temp txt file use a pipe:

Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry%  | Find /i "x86" 
If %ERRORLEVEL% == 0 (
    GOTO X86
) ELSE (
    GOTO X64
)


:X86

Commands here

GOTO END

:X64

commands here

:End
share|improve this answer

When you are using DEFINED, you must not enclose the variable name with % signs:

if defined ProgramFiles(x86) (
   :: do stuff for 64bit here
) else (
   :: do stuff for 32bit here
)
share|improve this answer

You may use the environment variable PROCESSOR_ARCHITECTURE to determine whether the process itself is running as 32-bit or 64-bit. The value is either AMD64 or x86.

You need to be careful though. If your batch file is being run from the 32-bit version of CMD.EXE (in \Windows\SysWOW64) this variable would be set to "x86", while it would be "AMD64" if from the CMD.EXE in \Windows\System32 on a 64-bit version of Windows.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .