How do I programmatically retrieve the actual path to the "Program Files" folder?

brasskazoo picture brasskazoo · Jul 6, 2009 · Viewed 39.4k times · Source

Possible Duplicate:
C# - How to get Program Files (x86) on Windows Vista 64 bit

I realize the odds of a user changing the Windows default of C:\Program Files is fairly slim, but stranger things have happened!

How can I get the correct path to Program Files from the system?

Answer

brasskazoo picture brasskazoo · Jul 6, 2009

.NET provides an enumeration of 'special folders' for Program Files, My Documents, etc.

The code to convert from the enumeration to the actual path looks like this:

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)

http://msdn.microsoft.com/en-us/library/14tx8hby.aspx