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?
-
This is a non-answer, but I have to suggest *not using the registry* if you can avoid it. This is .NET, so use a config file. – Steven Sudit Mar 30 '10 at 15:40
-
@Steven we have and still are considering using a config file. I just want to make sure before I build a case to change that code I have a solid understanding of how to accomplish this. – Achilles Mar 30 '10 at 15:47
-
Fair enough. I hope you succeed in building a case. – Steven Sudit Mar 30 '10 at 16:05
3 Answers
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.

- 69
- 1
- 8
-
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 Mar 31 '10 at 17:50
-
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 Apr 01 '10 at 08:19
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?

- 10,453
- 7
- 40
- 68
-
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 Mar 30 '10 at 15:52
-
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 Mar 30 '10 at 16:19
-
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 Mar 30 '10 at 16:32
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.

- 11,165
- 9
- 62
- 113