Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'd like to write a batch file, where some commands target items in the Program Files folder, that is naturally cross-compatible from Windows XP up to Windows 7 x64 and Server 2008 R2. However, the folder name I'd need in the 64-bit systems is Program Files (x86).

Is there a batch command that will allow me to detect the system architecture, and write an IF statement to use the appropriate folder? Alternately, is there a universally-applicable environment variable that will point me to the right folder? Or, would I have to set part of my script to look for the x86 folder and use it if present, only using the other folder if it's not?

share|improve this question

I can't remember where I found this, but you are welcome to it. I modified it to check for 32 bit and 64 bit Windows 7. It should be fairly self explanatory.

@echo off

ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt

if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

systeminfo | find "OS Name" > %TEMP%\osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7

echo %vers% | find "Windows Server 2008" > nul
if %ERRORLEVEL% == 0 goto ver_2008

echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_vista

goto warnthenexit


::Check if 32 or 64 bit
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt

    If %ERRORLEVEL% == 0 (
        :Run Windows 7 32 bit specific commands here.
        Echo "This is 32 Bit Windows 7"
    ) ELSE (
        :Run Windows 7 64 bit specific commands here.
        Echo "This is 64 Bit Windows 7"

goto exit

:Run Windows Server 2008 specific commands here.
echo Windows Server 2008
goto exit

:Run Windows Vista specific commands here.
echo Windows Vista
goto exit

:Run Windows Server 2003 specific commands here.
echo Windows Server 2003
goto exit

:Run Windows XP specific commands here.
echo Windows XP
goto exit

:Run Windows 2000 specific commands here.
echo Windows 2000
goto exit

:Run Windows NT specific commands here.
echo Windows NT
goto exit

echo Machine undetermined.

share|improve this answer
Wow. That's a lot longer and more detailed than what I was looking for, but nice! – Iszi Feb 16 '12 at 21:30

You can just check if ProgramFiles(x86) is empty or not. As long as no user or program set it manually.


IF "%ProgramFiles(x86)%"=="" GOTO 64 ELSE goto 86

ECHO %ProgramFiles(x86)%


ECHO %ProgramFiles%



Alternatively, you could check the variable PROCESSOR_ARCHITECTURE - if it's a 32-bit system it should be "x86", if it's a x86-64 it should be "AMD64", if it's an Itanium CPU it should be "IA64". I haven't tested the Itanium one, though. And I'm not sure what these would say in the case of a 32-bit Windows system being installed on a x86-64 machine.

These were checked/tested on Windows 7, and should work on Vista. Windows XP 64-bit has always been dodgy, though, so it might not work there.

share|improve this answer
32-bit Windows on a 64-bit machine reports x86. I had a 64-bit system that reported AMD64, but I'm pretty sure it had an Intel processor. – Iszi Feb 17 '12 at 0:47
@Iszi AMD64 is how Windows refers to x86-64 processors - both AMD and Intel ones. IA64 is a completely different architecture, and does not really apply since it does not support 32-bit programs. – Bob Feb 17 '12 at 0:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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