3

I want to write something like

%ProgramFiles(x86)%\someprogram\someprogram.exe

That would work in both Windows 32 and 64-bit versions

But:

  1. %ProgramFiles% points to the 32 bit program files folder only in 32bit Windows
  2. %ProgramFiles(x86)% points to the 32 bit program files folder only in 64bit Windows (it doesn't exist in 32-bit Windows)

Is there any Windows Environment variable that always point to the 32 bit program files folder, regardless of the Windows version?

1

2 Answers 2

3

You can always add %ProgramFiles(x86)% to the 32bit Windows platforms. You can use a simple command line to add it:

Set ProgramFiles(x86) = "C:\Program Files"

Then you have consistency across platforms.

Edit:

Since you told me what it is for, I would do something like this for your instructions:

1 - Change to the directory for the program. 

2 - open a command prompt 

3a - type "cd %programfiles(x86)%" 

3b - If  you receive the error "The system cannot find the path specified", 
     go to step 3c.  Otherwise go to 4. 

3c - type "cd %programfiles%" 

4 - Other stuff
4
  • You're right, but I need a solution that would work out of the box.
    – Jader Dias
    Sep 1, 2010 at 13:25
  • 1
    What are you using this for? I ask because if you are writing a script or installer, or a batch file, it is trivial to add this variable: IF %ProgramFiles(x86) == "" SET ProgramFiles(x86) = "C:\Program Files"
    – JNK
    Sep 1, 2010 at 13:29
  • I'm putting this path in the web as instructions to a not-so-smart audience
    – Jader Dias
    Sep 1, 2010 at 13:48
  • In that case, I would say make it a 2-part step. See edit to my answer.
    – JNK
    Sep 1, 2010 at 13:52
0

My first solution is:

  if "%ProgramFiles(x86)%" == "" (
    echo Win x86
    set PRGFILES=%ProgramFiles%
  ) else (
    echo Win x64
    set PRGFILES=%ProgramFiles(x86)%
  )
  echo 1: %PRGFILES%

The above solution caused some problems on first testing. It seemed like the ")" character in %ProgramFiles(x86)% caused end of if. Therefore secondary solution:

  if "%ProgramFiles(x86)%" == "" set PRGFILES=%ProgramFiles%
  if not "%ProgramFiles(x86)%" == "" set PRGFILES=%ProgramFiles(x86)%
  echo 2: %PRGFILES%

Tested only on Win 7 x64 and Win XP (x86).

According to my test it is better to use custom temporary environment variable and do not use direct the program files variables (above mentioned problems).

You must log in to answer this question.

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