WindowsRegistry - Finding out if a key exists

bool WindowsRegistry::keyExists (const String& regKeyPath)
{
    return RegistryKeyWrapper (regKeyPath, false, 0).key != 0;
}

bool WindowsRegistry::keyExistsWow64 (const String& regKeyPath)
{
    return RegistryKeyWrapper (regKeyPath, false, 0x100 /*KEY_WOW64_64KEY*/).key != 0;
}

Good idea, will add that, thanks!

…no, hang on, I’m confused - there’s already a valueExists method, so how is this different? Surely it’s impossible to have a key without a value?

Hopefully this link, and the following screenshot will explain… But it’s an entirely reasonable question, wanting to know if a registry key exists. How else would you find out if a certain type of software is installed, without checking a million folders? (ie: what if a user installs something NOT in program files, but some custom location, right?)
[attachment=0]Key, with a value not set.png[/attachment]

Ah yes, the meaning of “key” in the context of the win32 registry always confuses me. Thanks, will add that!

No worries, and thanks

I just got a problem with this function.

bool WindowsRegistry::keyExists (const String& regKeyPath)

It seems always return true even the key doesn't exist, but in earlier versions of Juce I seemed use it without any worry.

 

the bool WindowsRegistry::valueExists (const String& regKeyPath)

seems OK.


 

No.. I think you might be mistaken..

I tried

        bool b = WindowsRegistry::keyExists ("HKEY_CURRENT_USER\\Software\\dfgdfgs\\dfgdsfgdsfg");

and it did return false.

I tried with HKEY_CURRENT_USER tree too.

With keyExists() I get a true and with a valueExists() get a false, using the same string.

Thanks.

Can you give me an example of some actual code that you've run, and which does this?

You were right, the string was not build correctly, but I can't explain why it worked with valueExists().

Thanks, sorry for bothering.:-).

Hi,

I tried again with the proper string and I get the same result.

Here is my code:

juce::String PrefData::registry_radical;

void PrefData::set_registry_radical(void)

{
    if (registry_radical == juce::String::empty) {
        registry_radical = juce::String("HKEY_CURRENT_USER\\Software\\") + juce::String(COMPANY_STR) + juce::String("\\") + ProjectInfo::projectName + juce::String("\\");
    }
}

bool PrefData::progInstalled(void)

{
    juce::String x;

    set_registry_radical();
   
    x = registry_radical + juce::String(DATA_PATH_STR);
    if (WindowsRegistry::keyExists(x) == false) {
        return(false);
    }
    ......................................
    ......................................
}

I always get true with keyExists().

If I replace keyExists() with valueExists() I get the right result, according to the key exists or not.

I checked with debuger what contains x string, for me it seems OK.

So for now I use valueExists().