I have a .NET 3.5 application that has always run on x86 (XP). I now need this program to run on x64 (Win7). The build for this application is Any CPU so it should run on x64. In my setup project > Registry Editor I create a registry key called AppPath in HKEY_LOCAL_MACHINE\Software\Company\Product\AppPath.
On a 64 bit machine my setup project installs this key at HKEY_LOCAL_MACHINE\Software\Wow6432Node\Company\Product\AppPath
My first question is if I change the TargetPlatform of my Setup project to x64 why do the registry keys get added to the Wow6432Node subsystem? If I understand correctly targeting x64 should install the keys in the x64 registry not the Wow6432Node subsystem. Obviously I have not done everything required to target x64. What may I have missed that would cause the program to install as though it's 32 bit even though the setup project has a target platform of x64?
My second question is if I have code that reads the registry as follows:
clientPbDir = Registry.LocalMachine.OpenSubKey("Software\\Company\\Product").GetValue("AppPath").ToString();
How can I make this work for both x86 and x64?
This article kind of answers the question.
Reading the registry and Wow6432Node key
But I would prefer not have to compile my project as x86 just to be able to read the registry on both x86 and x64 if I can avoid it. I want to be able to make the most of x64 performance.