Registry redirection on 64-bit Windows

前端 未结 4 991
暗喜
暗喜 2021-01-20 16:47

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

What

相关标签:
4条回答
  • 2021-01-20 17:15

    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.

    0 讨论(0)
  • 2021-01-20 17:16

    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.

    0 讨论(0)
  • 2021-01-20 17:19

    Since you are targetting x86, simply using HKCU\Software\Classes\CLSID\{myguid}\InprocServer32 will work on all platforms.

    0 讨论(0)
  • 2021-01-20 17:25

    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.

    0 讨论(0)
提交回复
热议问题