1

I'm trying to get all the display name from the key: "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages"

and my code as follows:


using (RegistryKey baseKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages"))
            {
                foreach (string baseKeyName in baseKey.GetSubKeyNames())
                {
                    dosomething();
                }
                return false;
            }

After running and debugging the code above, i find the variable(basekey) is null so that the code will throw a exception.Although i have found some effective solutions that is just for .NET4.0 and higher, I wish get registry with .NET3.5. Is there any way for an application in 32bit mode to access the registry from 64bit system?

LittleBird
  • 11
  • 1
  • 1
    You might need to use the Win32 apis directly with the `KEY_WOW64_64KEY` flag – TheGeneral Mar 23 '20 at 02:57
  • 3
    Because of registry virtualisation you need to specify the `RegistryView` to open a different bitness Hive, However this feature is not available in .net 3.5, you can PInvoke it, or you can maybe target the `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...` <- note i haven't tried this – TheGeneral Mar 23 '20 at 03:05
  • I tried `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...`,it's not working as there is no directory called packages@Michael Randall – LittleBird Mar 23 '20 at 03:20
  • Have a look at this article [How to delete 64 bit Registry keys/values (.NET 3.5)](https://www.codeproject.com/Tips/425047/How-to-delete-64-bit-Registry-keys-values-NET-3-5), it might be helpful – Pavel Anikhouski Mar 23 '20 at 09:27
  • This existing thread can also be helpful [What are some alternatives to RegistryKey.OpenBaseKey in .NET 3.5?](https://stackoverflow.com/questions/26217199/what-are-some-alternatives-to-registrykey-openbasekey-in-net-3-5) – Pavel Anikhouski Mar 23 '20 at 09:27

0 Answers0