Solved

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

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

Expert Comment

by:Daniel Van Der Werken
Comment Utility
0
 
LVL 4

Author Comment

by:grishav
Comment Utility
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
Comment Utility


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

Author Comment

by:grishav
Comment Utility
@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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

13 Experts available now in Live!

Get 1:1 Help Now