I want to write .bat script which works under all flavours of Windows, no matter if 32 or 64 bit.
In this script I want to run some file.exe. That file is located in C:\Program Files\ under 32-bit systems or C:\Program FIles (x86)\ under x64 systems. I can write:
"%ProgramFiles(x86)%\file.exe" under 64bit systems or "%ProgramFiles%\file.exe" under 32bit systems but I want to make the script universal. Is there any way of determining that path universally?
To separate the 32-bit and 64-bit programs on your PC, Microsoft chooses to install 32-bit programs to the C:\Program Files (x86) folder.
On Windows editions that support x86 emulation, there are two directories for program files. The C:\Program Files directory is for programs in the native system bitness, and the the C:\Program Files (x86) directory is for programs that run under the x86-32 emulator.
While in the command prompt type "cd\", then enter. From there type "cd\program" then hit the tab button until you see "c:\program files (x86)", then hit enter.
You can get it from environment variable %ProgramW6432% . This variable exists on 64-bit Windows versions and always points to 64-bit instance of Program Files .
You could just check for its existence & store the path;
@echo off & setLocal enabledelayedexpansion
if exist "C:\Program Files\app1.exe" (
set PPATH="C:\Program Files\"
) else (
set PPATH="C:\Program Files(x86)\"
)
start "" %PPATH%app1.exe
start "" %PPATH%app2.exe
start "" %PPATH%app3.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With