# Create path to file under 64-bit %programfiles% from 32-bit process

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?

-
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
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

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

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

-