5

Problem is that in my case, a batch file run from 32 bit application have %ProgramFiles% expanding to "C:\Program Files (x86)".

3 Answers 3

6

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.

0
-1

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%
1
  • 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.
    – Ramhound
    Nov 11, 2022 at 18:22
-2

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

2
  • 1
    I don't see anything related to my question on that link. Please point the answer out, it there is any
    – user331681
    Jun 9, 2014 at 10:11
  • @user331681 - The accepted answer is the answer to this question.
    – Ramhound
    Jun 9, 2014 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .