Correct technique to find application in 32 and 64 bit versions of Vista/Windows 7 from CMD.EXE
11,689
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
Related videos on Youtube
Author by
user2666
Updated on September 17, 2022Comments
-
user2666 over 1 year
BACKGROUND
I have an existing CMD script that works fine. It launches an app from PROGRAM FILES like so
"%PROGRAMFILES%\MyApp\app.exe"
PROBLEM
- 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)
WHAT I AM LOOKING FOR
- 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.
-
bjoster about 3 yearsThis is incomplete and may fail on some (rare - but the question was for a "robust" solution) machines. Possible values for %processor_architecture% are
AMD64
,IA64
,ARM64
,EM64T
andX86
in which you script would fail in 3/5 cases.