简体   繁体   中英

Registry redirection on 64-bit Windows

I am running 64-bit Windows, and I want to create the registry key HKCU\\Software\\Classes\\Wow6432Node\\CLSID\\{myguid}\\InprocServer32 using C#.

What registry key should I tell it to write, so that it will be redirected to the above key? This should also work on 32-bit Windows.

I am compiling my app to target x86.

If you are using .net 4 you should make use of the RegistryView enumeration. Pass RegistryView.Registry32 when you call OpenBaseKey . Use HKCU\\Software\\Classes\\CLSID{myguid}\\InprocServer32 as your key and let the redirector do the work.

If you are using an older version of .net then I am afraid you will need to p/invoke the native Win32 API.

If you happen to be targetting x86 then you don't need to do anything. The registry redirector will do the right thing and redirect your registry access to the 32 bit view of the registry. You only need to take the steps outline above from a 64 bit process.

64-bit versions of Windows emulate 32-bit functionality through the "Windows on Windows" (WoW) subsystem.

In the case of the registry, they move the 32-bit keys over to a special subkey for compatibility reasons. It will automatically redirect 32-bit registry operations to HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node . More details can be found on the MSDN topic about the Registry Redirector .

You can use the RegistryView enum on RegistryKey.OpenBaseKey to open the 32-bit view explicitly and access HKCU\\Software\\Classes\\CLSID{myguid}\\InprocServer32 directly. This will automatically access the WOW64 node on 64-bit systems and the normal key on 32-bit systems.

由于您的目标是x86,因此只需使用HKCU\\Software\\Classes\\CLSID\\{myguid}\\InprocServer32在所有平台上运行。

By default your C# application is compiled using "Any CPU" (this is the default -- it means that your program will run as a x86 exe on x86 machine, and x64 on x64 machines). What you want to do is change the setting to Win32. Now your program will always run as an x86 exe, so it will be automatically redirected by windows the WOW6432Node. When you access the HKCU\\Software\\Classes\\CLSID{myguid}\\InprocServer32 on an x64 machine you will be redirected to the desired key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM