0
votes

I've registered COM component (shell extension). I've opened regedit and found registered CLSID on it. I need to check if key was registered in registry programmatically. So I've tried to found it from code: retrieved all subkeys from HKEY_CLASSES_ROOT\CLSID. And I got the set of ubkeys. But I can't see subkey with my CLSID on it ! Here is my code.

       var res2 = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry32)
                .OpenSubKey("CLSID")
                .GetSubKeyNames()
                .ToList();


        res2.ForEach(e => Console.WriteLine(e));

On image regedit vs my code results

I've tried to do smilar action on C++/WinAPI and have the same problem. Tried to run it "as admin" and on other PC with no success. So how could I get this subkey programmatically ?

1
Could be the classical x86 vs x64 issue. You may be looking at the 32-bit registry while your component is registered in the 64-bit registry, or vice-versa.Simon Mourier
Contrary to popular lore, you can't actually find a needle in a haystack. Regedit.exe sorts the keys by name, your program does not. That the console output looks sorted is an OS install accident. Do avoid HKCR, it is a virtual hive that was meant for 16-bit appcompat. Your installer wrote the key to HKLM/Software/Classes/CLSID. Now the RegistryView matters, since this is a shell extension you do want the 64-bit view.Hans Passant

1 Answers

2
votes

So, Yes need to change RegistryView.Registry32 => RegistryView.Registry64 Very stupid and silly mistake. Thank You all !