Click here to Skip to main content
12,075,610 members (66,619 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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)":

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 10-Sep-12 23:42pm
Edited 10-Sep-12 23:44pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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 :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

There is a quick fix to this programmatically:

string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
if (progfiles.EndsWith("(x86)"))
{
    progfiles = progfiles.Replace(" (x86)", "");
}
string progfilesx86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100