Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refer to 'Program Files' on a 64-bit machine

In C#, how do I refer the following locations rather than hard-coding them?

  • Program Files (x86)
  • Program Files
like image 700
Nemo Avatar asked Sep 21 '09 11:09

Nemo


People also ask

Which is 64-bit in Program Files?

The regular Program Files folder holds 64-bit applications, while "Program Files (x86)" is used for 32-bit applications.

What is C :\ Program Files x86?

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.

Should I install to Program Files or Program Files x86?

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.

Why does my PC have Program Files and Program Files x86?

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.


1 Answers

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.

like image 98
Simon P Stevens Avatar answered Oct 28 '22 10:10

Simon P Stevens