Correct technique to find application in 32 and 64 bit versions of Vista/Windows 7 from CMD.EXE

Solution 1:

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"
%AppExePath%

Solution 2:

This is the best that I could come up with:

set strProgramFiles=%ProgramFiles%
if exist "%ProgramFiles(x86)%" set strProgramFiles=%ProgramFiles(x86)%
"%strProgramFiles%\MyApp\app.exe"

Solution 3:

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
"%PROGRAMFILES(x86)%\MyApp\app.exe"
goto END

:32BIT
echo 32-bit Windows installed
"%PROGRAMFILES%\MyApp\app.exe"

:END