34

What happens when I use the environment variable %PROGRAMFILES(x86)% on a Windows OS that is 32bit (ie, older versions of Windows such as Windows XP, Vista)?

I am hoping that it will simply resolve to: C:/Program Files. Will this occur?

sazr
  • 24,984
  • 66
  • 194
  • 362
  • `%PROGRAMFILES%` will resolve to the folder for 64-bit programs, but there's nothing stopping you from making your own [%PROGRAMFILES (x86)%](http://stackoverflow.com/questions/17312348/how-do-i-set-windows-environment-variables-permanently) variable – Gary Aug 03 '15 at 17:55

4 Answers4

54

According to this the environment variable %PROGRAMFILES(x86)% is only available on 64-bit systems.

However, if you are on a 64-bit system and use %PROGRAMFILES%, the result you get depend on whether the process requesting the environment variable is 32-bit or 64-bit.

So from a 64-bit process on a 64-bit system you would get C:\Program Files, from a 32-bit process on a 64-bit system you would get C:\Program Files (x86), and from a 32-bit process on a 32-bit system you would get C:\Program Files.

If this doesn't help, perhaps you can comment or edit your original question to make it specific what you are trying to do. As it currently stands, the answer to your question is "No".

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • 1
    Thanks, It works how you say it works. A warning to people though that the Wikipedia entry is a bit misleading. – James_UK_DEV May 01 '14 at 13:06
  • 5
    How about "you would like to locate a specific 32-bit program using a batch file which is shared between 32 and 64 bit computers". To do this, you would need a variable which evaluates to c:\program files on a 32-bit system or c:\program files (x86) on a 64-bit system. i.e. %ProgramW6432% – OJW May 11 '15 at 13:40
  • 1
    So, the question is this: How to access the 64-bit path of program files, from a 32-bit software running on a 64-bit system? – Saeed Neamati Nov 29 '15 at 08:38
  • 1
    @SaeedNeamati You could use %ProgramW6432% as OJW notes above. This is described in more detail [in MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384274(v=vs.85).aspx). – Roger Rowland Nov 29 '15 at 09:33
  • 1
    If %ProgramW6432% gives you the 64-bit path, what's the answer to the original question "you would like to locate a specific 32-bit program..." stated by @OJW? – Jools Mar 01 '17 at 12:22
3

Keith Hill answered this question here, summary:

${env:ProgramFiles(x86)} is not defined on a 32-bit machine

If you always want to put/get data to/from x86 directory, then you can use this code to determine file paths:

$file = "\file"
if ("${Env:ProgramFiles(x86)}")
{
    $fullPath = "${Env:ProgramFiles(x86)}\$file"
}
else
{
    $fullPath = "${Env:ProgramFiles}\$file"
}
agabrys
  • 8,728
  • 3
  • 35
  • 73
2

Since %ProgramFiles(x86)% is not defined on Windows 7 32 bit, here is a workaround I came up with:

SET MyPath="%ProgramFiles(x86)%\MyFolder\MyApplication.exe"
rem workaround for Windows7 32 bit:
IF NOT DEFINED ProgramFiles(x86) SET MyPath="%PROGRAMFILES%\MyFolder\MyApplication.exe"

Use case: I want to call an application from a batch file that is installed:

  • on Windows 7 32 bit in C:\Program Files\MyFolder\MyApplication.exe
  • on Windows 7 64 bit in C:\Program Files(x86)\MyFolder\MyApplication.exe

This way %MyPath% always points to the correct path.

uceumern
  • 877
  • 10
  • 14
-15

If you use %programfiles% on a 32-bit computer/laptop it will open C:\Program Files.

If you use %programfiles% on a 64-bit computer/laptop it will open C:\Program Files.

If you have a 64-bit program installed on a 32-bit computer/laptop, it will be installed in a new folder named Program Files (x64), which is located in the "C" drive. In which case you have to use %programfiles(x64).

If you have a 32-bit program installed on a 64-bit computer/laptop, it will be installed in a new folder named Program Files (x86), which is located in the "C" drive. In which case you have to use %programfiles(x86).

Lee
  • 7
  • 2
    I'm guessing part of the reason people downvoted is because of the phrase `If you have a 64-bit program installed on a 32-bit computer/laptop`, which of course is so obviously impossible that it's nonsensical. – underscore_d Dec 21 '16 at 11:33
  • 1
    @underscore_d: I believe that you can run/install 64-bit code on a 32-bit OS, when running on a 64-bit ARM CPU. – IInspectable Mar 13 '18 at 09:58
  • @IInspectable It seems you're right. I'm glad I didn't downvote! However, I can't find much positive evidence that `Program Files (x64)` or `%programfiles(x64)%` are things that exist... are ARM users/discussions of Windows just that rare? Note the trailing `%` there, though; `%programfiles(x86)` will just be `echo`ed literally; we need `%programfiles(x86)%` to get the directory path. – underscore_d Mar 13 '18 at 12:56
  • @underscore_d: I haven't seen either a 64-bit program files directory nor the respective environment variable in the wild. Visual Studio comes with ARM64 build tools for desktop, though, so there must be Windows 10 desktop builds for ARM. I doubt, though, that the program files directory has an "x64" suffix, although I don't know, and compatibility has always been a strong argument for Microsoft to mis-name things. – IInspectable Mar 13 '18 at 18:02