Server Fault is a question and answer site for system and network administrators. 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 have an existing CMD script that works fine. It launches an app from PROGRAM FILES like so



  • it works fine on 32-bit versions of Windows (Vista, Windows 7)
  • but on 64-bit versions of Windows the app will be installed into "Program Files (x86)" and not "Program Files" (which is what happens on the 32bit OS)


  • A script that robustly handles both cases (i.e. it "does the right thing" depending on the OS it is on)
  • a method that uses only those features found in CMD.EXE. I Am curious about solutions that use Powershell, etc, but those don't help me - Powershell will not be on the machines this script will run.
share|improve this question
up vote 4 down vote accepted

Similar to Matt's correct answer. Basically in this version the complete path is verified.

SET AppExePath="%ProgramFiles(x86)%\MyApp\app.exe"
IF NOT EXIST %AppExePath% SET AppExePath="%ProgramFiles%\MyApp\app.exe"
share|improve this answer

This is the best that I could come up with:

set strProgramFiles=%ProgramFiles%
if exist "%ProgramFiles(x86)%" set strProgramFiles=%ProgramFiles(x86)%
share|improve this answer

Basically, you need to test for for the ProgramFiles(x86) environment variable to determine if you're in 64bit Windows or not. Here's a sample batch file.

if "%programfiles(x86)%zzz"=="zzz" goto 32BIT
echo 64-bit Windows installed
goto END

echo 32-bit Windows installed

share|improve this answer

Another approach is to run the script under the 32-bit cmd.exe, so that it can take advantage of WOW64 filesystem redirection and environment variable modifications. If you can modify the caller, you don't even have to modify the script in question.

You could even have the script detect when it's executing under the 64-bit cmd.exe and restart itself using the 32-bit cmd.exe:

@echo off
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto :x86
echo Restarting using Wow64 filesystem redirection: %0 %*
%SystemRoot%\SysWOW64\cmd.exe /c %0 %*
exit /b %ERRORLEVEL%

rem Rest of script follows...

Note that getting this hack wrong may result in spawning endless cmd.exe processes. That's why I used goto and a label instead of if ... ( ... ): command line parameters may contain parentheses, and if ... ( ... ) performs a greedy search for the first closing parenthesis.

share|improve this answer

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.