Solved

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

Posted on 2010-11-10
5
2,602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

729 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