views:

38

answers:

1

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

+2  A: 

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.

Hans Passant
I see. So in my code i have basically a switch to check for what im looking for in software and in software wow3264. I should probably just omit the switch and allow the framework to do what it wants without explicitly checking the wow 3264 node?
sweeney
You haven't described why this matters at all. It shouldn't.
Hans Passant
I'm checking for the presence of some potentially installed software packages. I inherited this code from some previous developers so they could have been totally off the mark as well, but the idea is that if i don't find the software in the normal subkey i check the wow subkey just to be certain. My app is compiled for x86 but will be installed on either platform.
sweeney
Sounds to me like you should be using WMI instead. Like Win32_Product. List is here: http://msdn.microsoft.com/en-us/library/aa390887%28VS.85%29.aspx Play with the WMI Code Creator tool. Start another question about it if necessary.
Hans Passant
Yea thats a much better idea, thanks. This is what i get for assuming the that the original devs knew what they were doing...
sweeney
Well, who does if they don't post to SO :) Close your thread please.
Hans Passant