Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ProgramFiles paths?

Tags:

c#

I have weird problem.

I`m using windows 7 enterprise sp1 64 bit.

I need to take Program files and Program files X86 directories path for my project. This is what I've done:

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); 

but both of these lines returns Program files X86 folder.

How can I resolve it?

like image 309
Ofir Avatar asked Oct 03 '12 14:10

Ofir


People also ask

How do I get to Program Files x86 in CMD?

While in the command prompt type "cd\", then enter. From there type "cd\program" then hit the tab button until you see "c:\program files (x86)", then hit enter.

How do I navigate to a program in command prompt?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.


1 Answers

This will work for x86, x64 or Any CPU configurations:

string programFiles = Environment.ExpandEnvironmentVariables("%ProgramW6432%"); string programFilesX86 = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"); 

Because using the environment variable ProgramW6432 will always return Program Files folder whereas ProgramFiles will vary depending on your application compilation options.

like image 169
David Avatar answered Sep 25 '22 12:09

David