Archive: Check Registrykey Exists


Check Registrykey Exists
Hi,

i want to check if a Registrykey exitst or not.
But I would not consider the key, but the folder in which it is located. In the folder, there is only the (standard) key.

Example:

To Check
HKLM "SOFTWARE\Test"

Not
HKLM "SOFTWARE\Test" "(Item)"



Can someone tell me how I can check?

Thank you


http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.6


Sorry, but this document, I have already read, but it has not helped me. Can you give me perhaps explain how I use the key to verify existens.
I would be very grateful to you.


Yeah, sure, here,

http://nsis.sourceforge.net/Reading_..._makes_it_easy


A comment on terminology: the "folders" in the registry are called "keys". They can contain other keys (subfolders) and "values" (which have the properties "name", "type", and "data").

Registry keys always have at least one value, the "default" value. Your screen shot shows this as "standard". You can test for the existence of a key by reading the default value.

ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Test" ""
${If} ${Errors}
# key does not exist
${EndIf}

Thanks demiller9 for you help.
but it doesn't works correctly.

if i run your code, i will allways jump to
# key does not exist

Can you help me pls.
thanks


There isn't any simple function in NSIS to check is registry key exist, but you can use EnumRegKey as workaround.

ClearErrors
EnumRegKey $0 HKCR "SOFTWARE\Test" 0
IfErrors 0 keyexist
# key does not exist
keyexist:


This will work because EnumRegKey will only set the error flag if there is errors so even if the key doesn't have any sub keys to "enum", it doesn't set the error flag.

GREAT!!!!!!!!!!!!!!

BIG THX!!!!!!
It works correctly!!! NICE!
Thanks


Originally posted by demiller9
A comment on terminology: the "folders" in the registry are called "keys". They can contain other keys (subfolders) and "values" (which have the properties "name", "type", and "data").

Registry keys always have at least one value, the "default" value. Your screen shot shows this as "standard". You can test for the existence of a key by reading the default value.
ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Test" ""
${If} ${Errors}
# key does not exist
${EndIf}
Yes they do have a default value name, but that value name has to have a value set for your code to work.

Stu