Here is a simplified example of a code I use in my XPCOM CPP DLL to check if a key exists in the registry.
It checks for the existance of 2 keys: HKLM\SOFTWARE\Microsoft
and HKLM\SOFTWARE\Microso
both exist with the same permissions, but the first one is found by this code and the second one is not... any idea why?
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) {
log("can't create @mozilla.org/windows-registry-key;1");
return -1;
}
NS_NAMED_LITERAL_STRING(key2,
"SOFTWARE\\Microsoft");
if (NS_FAILED(regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
key2, nsIWindowsRegKey::ACCESS_QUERY_VALUE))) {
// FAILED
LOG("regKey:: no such key");
}
NS_NAMED_LITERAL_STRING(key1,
"SOFTWARE\\Microso");
if (NS_FAILED(regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
key1, nsIWindowsRegKey::ACCESS_QUERY_VALUE))) {
// FAILED
LOG("regKey:: no such key");
}
EDIT: To make it clear, I've created a registry key myself, called HKLM\SOFTWARE\Microso
and I can access it through regedit
.