Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check location of 32bit Program Files folder in windows .bat script

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?

like image 890
Arek Avatar asked May 19 '10 10:05

Arek


People also ask

Where are 32-bit programs installed?

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.

What is the folder path for Windows 7 32-bit Program Files?

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.

How do I run Program Files x86 in CMD?

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.

How do I find Program Files x64?

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 .


1 Answers

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
like image 53
Alex K. Avatar answered Sep 25 '22 20:09

Alex K.