Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery - following an example but can I save data server side? 20 50
Scheduled Tasks Tweak 5 30
Windows updates batch files 7 42
Do Not Reply on Exchange 2010 1 12
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
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…
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…

773 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