Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have a process that runs as 32-bits regardless of the architecture. In it, I want to be able to spawn a process from the 64-bit program files menu (e.g. c:\program files instead of c:\program files (x86)\).

I tried using System.Environment.GetFolderPath, but for a 32 bit process, both SpecialFolders.ProgramFiles and SpecialFolders.ProgramFilesX86 returned the x86 folder. Ditto trying to use System.Environment.ExpandEnvironmentVariables("%programfiles%").

Instead I put together this mess:

Path.Combine(System.Environment.ExpandEnvironmentVariables("%systemdrive%") + @"\", @"Program Files\...");

The Path.Combine seems pretty useless since I've already put every '\' in there, so I simplified it to:

System.Environment.ExpandEnvironmentVariables("%systemdrive%") + @"\Program Files\...";

In my environment(s), the program files folder is always on the system drive, but the system drive has varying drive letters. Is there any better way to write this?

share|improve this question
    
Is there a reason why iy needs to be in \Program Files` instead of \Program Files (x86)`? –  James Khoury Dec 13 '12 at 3:48
    
@JamesKhoury, I'm trying to launch an app that's installed separately from mine. It only installs to Program Files. –  Jimmy Dec 13 '12 at 17:33
1  
I'd suggest a look at stackoverflow.com/questions/3916713/… ... I've not tried it but the answers seem to suggest searching the registry for it. Specifically: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths –  James Khoury Dec 13 '12 at 23:38
add comment

1 Answer

In the end, I made a slight simplification and ended up with:

System.Environment.ExpandEnvironmentVariables("%systemdrive%\Program Files\...")
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.