Solved

Environment.SpecialFolder.ProgramFiles returns c:\program files(x86)

Posted on 2010-11-10
5
2,521 Views
Last Modified: 2012-05-10
Hi,
My program is 32-bit managed application that run in 64-bit environment.
When I use
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
I got "c:\program files(x86)"
I need somehow to get the folder for 64-bit applications - i.e., c:\program files.
How can I get to this name?
Thanks
0
Comment
Question by:grishav
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 34102995
0
 
LVL 4

Author Comment

by:grishav
ID: 34103081
I saw this article. It offers the solution when I need to get c:\program files(x86) folder regardless of configuration.
My problem is different - I need to get "c:\program files"  folder from 32-bit application.
I don't think this article answers this question.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34103662


Environment.GetEnvironmentVariable("ProgramW6432", EnvironmentVariableTarget.Process)
0
 
LVL 4

Author Comment

by:grishav
ID: 34103735
@tgerbert,
Thanks for the answer, but I don't think this variable exist on Windows Server 2003 - I think MS added it only in Windows Server 2008 (at least according to the documentation).
Do you have any solution that will work for Windows Server 2003 ?
Thanks.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 34103975
Looks like you would need to use the Windows functions RegOpenKeyEx, RegQueryValueEx and RegCloseKey, using the flag KEY_WOW64_64KEY in your call to RegOpenKeyEx to get the 64-bit registry from a 32-bit application, then read the ProgramFilesDir value.
http://stackoverflow.com/questions/1958881/how-can-32-bit-application-find-the-location-of-64-bit-program-files-directory-on
Or, you can get the drive from the path to the windows folder and assume "\Program Files"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now