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
Solved

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

Posted on 2010-11-10
5
2,553 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
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 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

839 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