Using 64-bit Shortcuts from a 32-bit Application
Introduction
The WoW64 subsystem on 64-bit Windows emulates the environment of a 32-bit operating system when executing 32-bit applications.
This includes redirecting many 64-bit environment variables to their 32-bit equivalents.
The Wow64DisableWow64FsRedirection function temporarily disables the redirection for the System32 directory, it does not affect the Program Files directory.
For example a shortcut to the 64-bit version of Internet Explorer would launch the 32-bit version when run from a 32-bit application.
This behavior is a problem for applications that use 3rd-party plug-ins which place both the 32-bit and 64-bit plug-ins in the 64-bit Program Files folder and link to the plug in using a shortcut in the application's plug-ins folder.
When the 32-bit version of the application tries to load the 32-bit plug-in, it is redirected to the non-existent 32-bit location.
Code Sample
The code is available on the MSDN Code Gallery
Building The Sample
This sample requires Visual Studio 2010 or later.
Implementation
On Windows 7 and later the 64-bit Program Files location is exposed to 32-bit applications by the %ProgramW6432% environment variable.
if (IsWin7OrLater())
{
string programFiles = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
fixedPath = Path.Combine(programFiles, filePath);
}
On Windows Vista and earlier the 64-bit Program Files folder is resolved by removing the (x86) identifier from the 32-bit Program Files folder path.
const string x86 = "(x86)";
int index = ProgramFilesX86.IndexOf(x86, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
string programFiles = ProgramFilesX86.Remove(index, x86.Length).Trim();
fixedPath = Path.Combine(programFiles, filePath);
}
The SysWOW64 shortcuts are resolved by replacing SysWOW64 with System32.
string fixedPath = fullPath.Replace("SysWOW64", "System32");
if (File.Exists(fixedPath))
{
return fixedPath;
}