111

I would like to know how I can display the location of Program Files (x86) in command prompt. I'm using Windows 7 64bit.

I've tried:

echo %programfiles(x86)% and echo %programfiles%,
both of which displays only C:\Program Files

When I manually checked the registry,
HKLM/Software/microsoft/windows/currentversion,
the programfilesdir points to C:\Program Files and

HKLM/Software/WOW64/Microsoft/winodws/currentversion,
the programfilesdir points to C:\Program Files (x86).

But, why am I always being displayed with C:\Program Files??

Share a link to this question
CC BY-SA 3.0
| improve this question | |
  • 11
    I think the real question is, why isn't there a version of %programfiles% that always points to x86 on both windows 7 and windows xp to simplify running programs that are installed on both? For example, after installing Debugging Tools for Windows (x86) on XP, it's found in Program Files but on Windows 7 it's found on Program Files (x86) which means there's no simple way to create a command file that can be distributed across all computers since none of the built-in environment variables consistently point to the 32-bit location for Program Files. – dj69 Oct 11 '13 at 13:17
  • [posted after reading all answer] IMHO, one point that is missing in this discussion is that whatever variable you use, it is guaranteed to always point at the appropriate folder. This becomes critical in the rare cases where Windows is installed on a drive other than C:\. – Amir Katz Aug 14 at 11:25
183

On a 64-bit machine running in 64-bit mode:

  • echo %programfiles% ==> C:\Program Files
  • echo %programfiles(x86)% ==> C:\Program Files (x86)

On a 64-bit machine running in 32-bit (WOW64) mode:

  • echo %programfiles% ==> C:\Program Files (x86)
  • echo %programfiles(x86)% ==> C:\Program Files (x86)

On a 32-bit machine running in 32-bit mode:

  • echo %programfiles% ==> C:\Program Files
  • echo %programfiles(x86)% ==> %programfiles(x86)%
Share a link to this answer
CC BY-SA 3.0
| improve this answer | |
  • 18
    What %programfiles(x86)% will return on 32-bit machine in 32-bit mode? – Ivan Kochurkin Jan 13 '14 at 12:08
  • On windows XP (x86) doesn't work, you need put %programfiles%. I think the only way is to check by code the OS version first and then use one variable or other. – gsubiran Feb 5 '14 at 16:12
  • 3
    It might be worth adding %ProgramW6432% to the list above. – Alex Wiese Apr 14 '16 at 5:26
  • 2
    The same applies to 32-bit version of Windows 7 - there is no %programfiles(x86)% environmental variable – badsamaritan Jun 20 '16 at 10:19
  • 1
    I second @Alex Wiese, %ProgramW6432% will have the 64-bit program files directory, always. %ProgramFiles(x86)% will have the 32-bit program files directory, always. Those two variables are stable... the others may change depending on what mode the 64-bit OS (or command prompt) is running in. – Jason Feb 8 '17 at 16:33
36

Another relevant environment variable is:

%ProgramW6432%

So, on a 64-bit machine running in 32-bit (WOW64) mode:

  • echo %programfiles% ==> C:\Program Files (x86)
  • echo %programfiles(x86)% ==> C:\Program Files (x86)
  • echo %ProgramW6432% ==> C:\Program Files

From Wikipedia:

The %ProgramFiles% variable points to the Program Files directory, which stores all the installed programs of Windows and others. The default on English-language systems is "C:\Program Files". In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)%, which defaults to "C:\Program Files (x86)", and %ProgramW6432%, which defaults to "C:\Program Files". The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).

Reference: http://en.wikipedia.org/wiki/Environment_variable

Share a link to this answer
CC BY-SA 3.0
| improve this answer | |
  • 3
    Better reference: MSDN: WOW64 Implementation Details - "The ProgramW6432 and CommonProgramW6432 environment variables were added starting with Windows 7 and Windows Server 2008 R2." Wikipedia directly contradicts this; interestingly, Wikipedia only lists the three versions that don't support this variable according to MSDN. Unfortunately I don't have 64-bit XP/Vista to test. – Lexikos Oct 20 '15 at 21:40
  • 1
    On second read, I see that the Windows 7/2008 R2 requirement only applies to 64-bit processes. The variable is defined only for 32-bit processes on Vista x64. – Lexikos Oct 20 '15 at 21:56
4

On a Windows 64 bit machine, echo %programfiles(x86)% does print C:\Program Files (x86)

Share a link to this answer
CC BY-SA 3.0
| improve this answer | |
0

IMHO, one point that is missing in this discussion is that whatever variable you use, it is guaranteed to always point at the appropriate folder. This becomes critical in the rare cases where Windows is installed on a drive other than C:\

Share a link to this answer
CC BY-SA 4.0
| improve this answer | |
  • 1
    This is a good note. But since it's not answering the question directly, it would have been better to write it as a comment to the question itself. – AbstractVoid Aug 3 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.