Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registry GetSubKeyNames() lists different keys than Regedit?

Tags:

We are using WIX to install a number of services we create. I am writing a quick utility to dump the currently installed services. I just iterate over subkeys of:

SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  

looking for DisplayName. The problem is, only two of my ten services show up in the list.

However, when I look at the subkeys in Regedit, they are there. As well, they are in the installed programs (and I can find them in SELECT * from Win32_Product too).

I looked through the MSDN docs, trying to find out if there is some special view of the registry that I am missing. Maybe it is a privilege issue? But I am running the tool as admin. Is there some hive mounting issue?

Just to be clear with the code, here is the test app code (from this answer):

String registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) {   foreach(String subkeyName in key.GetSubKeyNames())     Console.WriteLine(key.OpenSubKey(subkeyName).GetValue("DisplayName")); } 

Any thoughts on this?

like image 792
teleball Avatar asked Jun 24 '10 17:06

teleball


1 Answers

The problem is a 32/64 bit issue. It seems that some of the installations happened under

HKEY_LOCAL_MACHINE\Software\Wow6432Node\...  

When I enumerate them both, I get all of my installations.

Apparently I can also use RegistryKey.OpenBaseKey() with a RegistryView.Registry64/32 instead of the Wow6432Node too.

like image 67
teleball Avatar answered Oct 17 '22 06:10

teleball