Using %Programfiles(X86)% on Windows Os 32Bit

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?

1

4 Answers

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".

5

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"
}

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.

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).

4

Your Answer

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

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest