How to get 64-bit “program files” directory in 32-bit Application


In Build Settings, uncheck the option Prefer 32-bit. Now Environment.SpecialFolder.ProgramFilesX86 will return a 32-bit path and Environment.SpecialFolder.ProgramFiles will return a 64-bit path.


I have an application compiled in x86 mode (in c#) from which I need to access a certain file that exists in the 64-bit program files folder (of a 64-bit Windows of course). I don't want to just hardcode C:\Program Files as a string in my application because a few target computers may have Windows installed in a different drive, or may be in another languages.

The problem I'm encountering is that using Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) returns the x86 flavor instead of the desired directory, unless I compile my program in 64-bit mode. Out of curiosity, what can I do to avoid doing such?