In C#, how do I refer the following locations rather than hard-coding them?
The regular Program Files folder holds 64-bit applications, while "Program Files (x86)" is used for 32-bit applications.
On Windows editions that support x86 emulation, there are two directories for program files. The C:\Program Files directory is for programs in the native system bitness, and the the C:\Program Files (x86) directory is for programs that run under the x86-32 emulator.
It doesn't normally matter whether a program's files are stored in Program Files or Program Files (x86). Windows automatically installs programs to the correct folder, so you don't have to think about it. Programs appear in the Start menu and function normally, no matter where they're installed.
The Windows separated and created two different directories of the 32-bit program and 64-bit program. The Program Files stores all the 64-bit programs and the Program Files (x86) stores all the 32-bit programs. x86 stands for different processor types, i.e. 286, 386, 486, 586/Pentium.
You can use:
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);
to get the program files folder on the machine. This will return whatever is correct for the application that is running. So for 32-bit applications on a 64-bit machine, it will return "C:\Program Files (x86)" on a English version of Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With