Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

The problem im having involves the ProgramFiles and ProgramFiles(x86).

I don't know if this is just a problem with my machine being Windows 8 or it being 64bit but the following both resolve to "C:\Program Files (x86)":

C#
string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string progfilesx86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);


Using other sources i can see other people have had this problem but is there any way around it that anyone knows?
Thanks!
Posted
Updated 10-Sep-12 22:44pm
v2

it depends on the Target platform of your app.. If you set it x64 build, and you run it on x64 machine you should get Program Files. On the other hand if it's x86 target platform then you get C:\Program Files (x86) even if you execute it on x64 machine
 
Share this answer
 
Comments
MitchG92_24 11-Sep-12 5:02am    
Thanks Kuthuparakkal, i should really pay attention to these background settings!
Kuthuparakkal 11-Sep-12 5:17am    
np :)
There is a quick fix to this programmatically:

C#
string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
if (progfiles.EndsWith("(x86)"))
{
    progfiles = progfiles.Replace(" (x86)", "");
}
string progfilesx86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900