Archive: Registry reading problems...


Hi,

Does anyone know why this doesn't work:

ClearErrors
ReadRegStr $1 HKLM "SECURITY" ""
IfErrors lbl_err lbl_ok

lbl_err:
MessageBox MB_ICONEXCLAMATION "ERROR: [$1]"
GoTo lbl_end

lbl_ok:
MessageBox MB_ICONEXCLAMATION "NO ERROR: [$1]"
GoTo lbl_end

lbl_end:

All I want to do is to check if the "SECURITY" key (in this case) exists. The result I get is "ERROR: []". I know that there are no keys below "SECURITY".

Thanks,
Aarif


hi,

when an error occurs, the string in the variable will always return an empty string, that's why you get "ERROR[]".

try it like that:

ClearErrors
ReadRegStr $1 HKLM "SECURITY" ""
IfErrors lbl_err lbl_ok

lbl_err:
MessageBox MB_ICONEXCLAMATION "ERROR!"
GoTo lbl_end

lbl_ok:
StrCmp $1 '' lbl_error
MessageBox MB_ICONEXCLAMATION "NO ERROR: [$1]"

lbl_end:

cu yzo


I understand that. My problem is that the key should be there, so I shouldn't get an error. It should say "NO ERROR []".

Aarif


The problem is that ReadRegStr expects a data entry name, and returns the value. A registry key ("SECURITY" in this case) does not have any data associated directly with it; it is like trying to open a directory as if it were a file. An error will always be returned.

There is currently no way for NSIS to find if a registry key exists, short of trying to read a name/value pair from inside that key. Since there is no data stored in the SECURITY key, there is no way to detect it currently in NSIS.

You can suggest such a function to justin (email him, I think its justin@winamp.com but check before you send), and he may implement it in the next release. Or else install the source code and make the changes yourself :)


The 4th parameter I passed to the ReadRegStr command was a "", because I wanted to get the value of the "(Default)" entry. The default entry exists for all registry keys and may sometimes have a value. If you look at the registry using regedit, you will see a default entry for all keys. If passing an empty string as the 4th parameter is not the way to get this value, then how do I do it?

Aarif


hi,

Aarif: the way you did it is correct!

it reads the default value of the registry key
(,and also checks the existense of the key .. sure, if an error occurs the key doesn't exist)

and here is your problem!

the key HKLM SECURITY doesn't exist, as it is case-sensitive and should read "Security"

try it like that and it will work!

cu yzo