amokk
11th March 2008 21:28 UTC
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
amokk
12th March 2008 15:00 UTC
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.
demiller9
12th March 2008 16:19 UTC
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}
amokk
12th March 2008 17:28 UTC
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
{_trueparuex^}
12th March 2008 18:11 UTC
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.
amokk
13th March 2008 11:31 UTC
GREAT!!!!!!!!!!!!!!
BIG THX!!!!!!
It works correctly!!! NICE!
Thanks
Afrow UK
13th March 2008 11:33 UTC
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