Old 2nd October 2015, 20:07   #1
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
Question 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?
zewari is offline   Reply With Quote
Old 2nd October 2015, 22:47   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
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:
Quote:
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 23rd October 2015, 18:05   #3
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
Thanks Anders, placing the dll in the ANSI folder made the plugin work for me.
zewari is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump