Problem is that in my case, a batch file run from 32 bit application have %ProgramFiles% expanding to "C:\Program Files (x86)".
3 Answers
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
.
In a batch file is spawned by a 32bit exectutable, I found that all ProgramFiles related environment variables contain the "Program Files (x86)" location. As a kludge, you can assume the 64bit folder is on the same drive, but lacks the " (x86)" substring at the end. The value with the substring stripped may be computed in batch as follows:
set Programs=%ProgramFiles(x86)%
set Programs64=%Programs:~0,-6%
-
Determining the environment, before setting an internal variable, is the proper solution. Just blindly stripping 6 characters does not seem like a very good idea.– RamhoundNov 11, 2022 at 18:22
Read this SO for your answer: https://stackoverflow.com/questions/10071300/how-to-create-a-batch-file-which-work-for-both-program-files-and-program-filesx
It uses environment variables to identify x86 and 64-Bit Program Files folders
-
1I don't see anything related to my question on that link. Please point the answer out, it there is any Jun 9, 2014 at 10:11
-