teleball teleball - 1 year ago 103
C# Question

Registry GetSubKeyNames() lists different keys than Regedit?

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:


looking for
. 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())

Any thoughts on this?

Answer Source

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download