views:

254

answers:

1

I'm programming in C#.NET. I want to be able to return the Program Files directory from the target machine no matter what the architecture of the target machine is. To clarify, I want it to return C(or whatever drive the OS is on):/Program Files no matter what bittness their version of windows is.

I could just hardcode in the directory except if the used was running windows that's not installed on the C: drive it wouldn't work.

I found this... FileInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) but I think it returns the Program Files (x86) folder on a 64 bit windows machine.

+4  A: 

System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) returns "c:\Program Files" on a 64-bit machine, unless the code is build to target x86, in which case it returns "C:\Program Files (x86)", so I guess that would work for you.

Fredrik Mörk
What if the target platform is set to Any CPU?
Jordan S
If I compile code using Any CPU on my 64-bit machine it returns `"C:\Program Files"` (verified it just now).
Fredrik Mörk
I did too and it returns Program Files (x86) on mine...
Jordan S