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?
\Program Files` instead of
\Program Files (x86)`? – James Khoury Dec 13 '12 at 3:48Program Files
. – Jimmy Dec 13 '12 at 17:33HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
– James Khoury Dec 13 '12 at 23:38