gclass
26th February 2012 18:53 UTC
Reading registry key
Hello,
I would like to read a registry key while installation process.
if the key exist, a plugin is already installed on machine.
if the key is missing I need NSIS to install the plugin before proceeding with main software.
would like to ask your help if the code I am using is OK and I wont have troubles on other machines (works fine on my testing machine):
ReadRegStr $0 HKCR "AppID\{AGDGD-4504-JJSK-JSIE-HDGD84747}" "instl"
${If} ${Errors}
StrCpy $instplugin yes
${Else}
StrCpy $instplugin no
${EndIf}
thx
MSG
27th February 2012 06:13 UTC
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.12
As you can see, the error flag is set in more cases than just a nonexisting string.
gclass
27th February 2012 09:00 UTC
MSG thank you for reply.
as I read, the error flag will be set if:
- the value is empty.
- the type is REG_DWORD.
according to the plugin developer, "the plugin is installed if the key is string type and verify size>0"
if I get it right, I need to check that the key is holding a string with value bigger than 0, all other options indicate the plugin is not installed, am I correct?
thx
MSG
27th February 2012 10:02 UTC
If you're asking what the developer meant, how should I know? You should ask the developer.
To make sure if a registry key contains a value, you can simply check if it returns "".
gclass
27th February 2012 10:09 UTC
:) I wasnt meant to ask you what the developer meant.
I meant to ask if the code I am using is correct in case I want to check a registry key to be string type and not empty (given I will check the value is bigger than 0)
thx
Afrow UK
27th February 2012 11:23 UTC
You should add a ClearErrors before the registry read.
Stu
gclass
27th February 2012 11:39 UTC
Thx Stu
ClearErrors
ReadRegStr $0 HKCR "AppID\{AGDGD-4504-JJSK-JSIE-HDGD84747}" "instl"
${If} ${Errors}
StrCpy $instplugin yes
${Else}
StrCpy $instplugin no
${EndIf}
simple as that?
Afrow UK
27th February 2012 11:52 UTC
Actually I agree with MSG, you should be checking the value is not an empty string. The error flag won't be set if the value is an empty string (i.e. because a value is still set). It'll be set if the value is the wrong type or does not exist.
Stu