3

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!

Community
  • 1
  • 1
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • @BaliC, I don't readily have access to 32-bit systems inside my organization -- it doesn't work like that where I work -- I can't just stand up machines -- so I was hoping the community could help me out. Simple. – Mike Perrenoud Dec 18 '12 at 15:32
  • Sorry, I just realised that and deleted my comment, I found your answer in a related question, check the comments http://stackoverflow.com/a/4514110/799586 – Bali C Dec 18 '12 at 15:34
  • 2
    _"I don't readily have access to 32-bit systems inside my organization -- it doesn't work like that where I work"_ - does your company hate developers, or just doesn't want them to be productive? – CodeCaster Dec 18 '12 at 15:41
  • @CodeCaster, I hear you loud and clear brother! – Mike Perrenoud Dec 18 '12 at 15:46

4 Answers4

23

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.

Ivan Krivyakov
  • 1,898
  • 1
  • 17
  • 27
3

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
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
1

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.

Peter Ruderman
  • 12,241
  • 1
  • 36
  • 58
1

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

Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86));
Barry Kaye
  • 7,682
  • 6
  • 42
  • 64