When attempting to determine the presence of a software on a user's machine, using the path System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles)MyInstalledApp may lead to inaccuracies on 64-bit Windows Vista. This is because the code returns the x64 "Program Files" folder, while the application in question resides in "Program Files (x86)".
To alleviate this issue, you can employ the following function, which will consistently return the x86 "Program Files" directory across all configurations:
static string ProgramFilesx86() { if (8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))) { return Environment.GetEnvironmentVariable("ProgramFiles(x86)"); } return Environment.GetEnvironmentVariable("ProgramFiles"); }
In this function:
The above is the detailed content of How to Reliably Get the 'Program Files (x86)' Path on 64-bit Windows?. For more information, please follow other related articles on the PHP Chinese website!