Search code examples
c#special-foldersprogram-files

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

Solution

  • 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.