Here's an idea for performing the task, which assumes that you're happy to run the executable regardless of whether an existing version of Firefox
is already installed or not.
@Echo Off
If Defined PROCESSOR_ARCHITEW6432 (
Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0"&Exit /B)
If %PROCESSOR_ARCHITECTURE:~-2% Equ 86 (Call :Sub 32)Else Call :Sub 64
Pause
GoTo :EOF
:Sub
For %%A In ("%~dp0Firefox-*-%1.exe")Do (Start "" /Wait "%%A"
If Not ErrorLevel 1 Echo Done)
Exit /B
This works by ensuring that the appropriate version of cmd.exe
is running the batch file first. This is necessary because if the 32-bit version of cmd.exe
is running the script on a x64
system, the %PROCESSOR_ARCHITECTURE%
variable value will be x86
. However when the 32-bit version of cmd.exe
is running on a x64
system, a new environment variable %PROCESSOR_ARCHITEW6432%
is defined, which does not exist in 64-bit cmd.exe
on a x64
system, or 32-bit cmd.exe
on a x86
system. Once the script is running in the correct bitness version of cmd.exe
, we can rely on the output of %PROCESSOR_ARCHITECTURE%
for running the appropriate executable.
As an additional comment, the Firefox executables, which are essentially just self-extracting 7z archives, appear to have exactly the same name, regardless of which bitness version you download, e.g. Firefox Setup 66.0.2.exe
. This means that the executables in the question must have been been renamed, and so you could rename them to anything at all you want. If you use the same renaming scheme, but instead use -86
instead of -32
you could simplify the code a little too:
@Echo Off
If Defined PROCESSOR_ARCHITEW6432 (
Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0"&Exit /B)
For %%A In ("%~dp0Firefox-*-%PROCESSOR_ARCHITECTURE:~-2%.exe")Do (
Start "" /Wait "%%A"
If Not ErrorLevel 1 Echo Done
Pause)