How to get ProgramFiles paths?

The result depends on what platform is your project targeting. If you target x86, then both Environment.SpecialFolder.ProgramFiles and Environment.SpecialFolder.ProgramFilesX86 will return the same path.


This will work for x86, x64 or Any CPU configurations:

string programFiles = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
string programFilesX86 = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%");

Because using the environment variable ProgramW6432 will always return Program Files folder whereas ProgramFiles will vary depending on your application compilation options.

Tags:

C#