I am working on a C# project and I am using the following code:
string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
However, when I look at the rootPath, it's set to C:\Program Files (x86).
Why would do it this as there is an Environment.SpecialFolder.ProgramFilesX86
which I would have thought would have returned the above.
If your project is currently targeting the x86
platform, both of those enum values will return the Program Files(x86)
directory.
Change the target platform for your project to x64
, and SpecialFolder.ProgramFiles
should return the Program Files
directory instead.
I have a scenario where i could not change the target of the executing assembly. So i use this method to get always the x64 (also when running in 32bit):
var programFilesX64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion")?.GetValue("ProgramFilesDir");
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