Question

Since I can't find anything clearly stating it on the MSDN documentation: what does the ProgramFilesX86 enum value return on 32-bit systems?


Development Environment

Please note: in my organization I can't just stand up machines whenever I want to test things. This is why I'm asking the community. I don't even have access to 32-bit ISO's to build a virtual machine -- so please understand I have some limitations inside this organization.

  • Windows 7 64-bit

Production Environment

In production I don't know if they are running 32 or 64-bit systems, and it's likely a mixture. However I do know the list of operating systems.

  • Windows 7
  • Windows Vista
  • Windows XP

Objective

Get the correct program files directory so I can launch my application dynamically.

Known Variables

  1. The application is installed with an MSI, and it will be installed with the default options, so it will be installed in the Program Files directory.
  2. The application is a 32-bit application, so on 64-bit systems it will use the Program Files (x86) folder, but on 32-bit systems it will use the standard Program Files directory.

Thanks all!

Was it helpful?

Solution 3

It returns "Program Files". Since you're installing using an MSI, you might consider using the installer APIs (MsiLocateComponent, and so on) to locate your program instead of assuming it's in the expected location.

OTHER TIPS

32-bit XP: an empty string :(
32-bit Vista: "C:\Program Files"
32-bit Win7: not tested, probably same as Vista
64-bit Win7: "C:\Program Files (x86)"

Not sure about 64-bit XP, I am curious myself.

The Remarks section for KNOWNFOLDERID contains a handy table giving you the information you seek (from an unmanaged perspective). It's tricky to reproduce it here:

OS      App     KNOWNFOLDERID               Default                             CSIDL
32 bit  32 bit  FOLDERID_ProgramFilesX86    %SystemDrive%\Program Files         CSIDL_PROGRAM_FILESX86
64 bit  64 bit  FOLDERID_ProgramFilesX86    %SystemDrive%\Program Files (x86)   CSIDL_PROGRAM_FILESX86
64 bit  32 bit  FOLDERID_ProgramFilesX86    %SystemDrive%\Program Files (x86)   CSIDL_PROGRAM_FILESX86

On my Win 7 32-bit system ProgramFilesX86 returns C:\Program Files (no trailing slash).

Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top