Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegistryKey.GetSubKeyNames returns names that are not in that subkey!

Tags:

c#

registry

This can't be right but it's happening to me. I have the following function:

private static bool KeyExists(RegistryKey key, string search)
{
    //GetSubKeyNames is busted...
    foreach (string subKey in key.GetSubKeyNames())
    {
        if (subKey.Trim().Equals(search.Trim()))
        {
            return true;
        }
    }
    return false;
}

If I put the line String[] names = key.GetSubKeyNames() and have a look in the debugger, I see that the listed names are not what I see in regedit. For example I have a piece of software installed which appears in the Wow6432Node subkey but it pops up if I search for it in the normal Software subkey. Any ideas?

Thanks, brian

like image 647
Brian Sweeney Avatar asked Dec 05 '25 20:12

Brian Sweeney


1 Answers

The Wow6432 key contains the registry keys that a 32-bit program sees. Project + Properties, Build tab, check your Platform target setting. It defaults to x86 in VS2010.

Registry redirection can be changed but not with the .NET RegistryKey class. You'd have to pinvoke the registry API functions. More background info is available in the SDK.

like image 187
Hans Passant Avatar answered Dec 08 '25 10:12

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!