Skip to content
⌘ NSIS Forum Archive

Verifying if registry key exists in 3.0b

3 posts

zewari#

Verifying if registry key exists in 3.0b

Hey folks,

I was hoping to port my old nsis installer to 3.0b, which uses this registry plug-in, but it wasn't able to recognize the plug-in. My only use of it was to leverage its call for validating the existence of a registry key. What other method can I use to accomplish this task?
Anders#
Posting the warnings/errors you get from the compiler is always helpful! I assume you are getting a "Plugin not found, cannot call" message and this should be your clue that you need to put the .dll in the correct subdirectory inside NSIS\Plugins\. It looks like that plugin only has a ANSI version so you should put it under x86-ansi and you will not be able to generate Unicode installers that use that plugin.

You can also use one of the other registry plugins or perform the check manually:
Function RegKeyIsNonEmpty ; <HKCU|HKLM> <Key>
Exch $2
Exch 1
Exch $1
Push $0
ClearErrors
StrCmp HKLM $1 0 +3
EnumRegValue $0 HKLM $2 0
Goto +2
EnumRegValue $0 HKCU $2 0
IfErrors +2
StrCpy $0 1 ; Make sure the default value ("") is treated as success
StrCmp $0 "" 0 ret
StrCmp HKLM $1 0 +3
EnumRegKey $0 HKLM $2 0
Goto +2
EnumRegKey $0 HKCU $2 0
ret:
StrCpy $2 $0
Pop $0
Pop $1
Exch $2
FunctionEnd

Function RegKeyExists ; <HKCU|HKLM> <ParentKey> <SubKey>
Exch $3
Exch 1
Exch $2
Exch 2
Exch $1
Push $0
Push $4
StrCpy $4 0
loop:
StrCmp HKLM $1 0 +3
EnumRegKey $0 HKLM $2 $4
Goto +2
EnumRegKey $0 HKCU $2 $4
IntOp $4 $4 + 1
StrCmp $0 $3 +2 ; Found it?
StrCmp $0 "" 0 loop
StrCpy $2 $0 ; Set return value
Pop $4
Pop $0
Pop $1
Pop $3
Exch $2
FunctionEnd

Section
Push HKCU
Push "Software\NSIS\MRU"
Call RegKeyIsNonEmpty
Pop $0
StrCmp $0 "" 0 +3
DetailPrint "Key is empty or does not exist"
Goto +2
DetailPrint "Key exists and is not empty"

Push HKCU
Push "Software\NSIS"
Push "Symbols"
Call RegKeyExists
Pop $0
StrCmp $0 "" 0 +3
DetailPrint "Key does not exist"
Goto +2
DetailPrint "Key exists"
SectionEnd