views:

211

answers:

3

We have an legacy application that accesses the registry. Because it is a 32bit application it accesses the registry in Windows 7 through Registry Virtualization when referencing HKEY_LOCAL_MACHINE\Software. My question is what setting(s) in Visual Studio do we need to modify to compile our applications where they access the registry "normally" without going through Registry Virtualization?

A: 

Why don't you use:

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\...");
return (string)key.GetValue("blah");

and add access to the registry in the customtrust.config file.

or doesn't that work in Windows 7?

Bravax
That code works, but not for this old application. I read documentation and it states that if the application isn't compatible with Windows 7 then its registry access is routed to a different location using Registry Virtualization http://msdn.microsoft.com/en-us/library/aa965884(VS.85).aspx
Achilles
That's interesting, I didn't know that existed. Could you impersonate a user that has access to the registry key? That would remove the use of Registry Virtualization.
Bravax
The problem I'm facing is that the application configures a global registry location that multiple applications access. The applications can't find the settings because they are being stashed away in this virtual location.
Achilles
+1  A: 

If you read the Registry Virtualization page closely, you will notice that the virtualization is not limited to 64-bit Windows. It only states that only 32-bit processes will be virtualized. But the virtualization is done on both 32- and 64-bit Vista and later. So the question title and the x64 tag are a bit misleading.

To answer your question, the same page says this: "Registry virtualization is disabled for the following: ... Processes that have requestedExecutionLevel specified in their manifests."

So you can disable the virtualization by adding a manifest file to your executable that specifies its execution level. There is at least a Microsoft KB article for how to do it in Visual Studio 2005: http://support.microsoft.com/kb/944276.

peruukki
Wouldn't compiling the application to 64bit work too?
Achilles
Yes, that would also work for the Registry Virtualization problem.However, the embedded manifest has other advantages too. It shows that the application is "Vista/Win 7 aware", and it specifies whether the application needs to run with administrator or standard user privileges. I would definitely recommend adding it in any case.
peruukki
Oops, I forgot to mention that since the registry virtualization happens on both 32- and 64-bit OS, the only legitimate solution I know on 32-bit Windows is to create the manifest.
peruukki
A: 

The solution was to compile the legacy application to target x64. An application that is explicitly targeting x64 will not be subject to registry virtualization.

Achilles