You are here

NSIS problem with variables

4 posts / 0 new
Last post
Benedikt93
Offline
Last seen: 9 years 4 months ago
Joined: 2009-12-17 14:46
NSIS problem with variables

I'm doing a piece of NSIS at the moment to backup registry keys or values found by a search in the registry.
As it's almost finished, I wanted to do a quick test, but the NSIS compiler always gives me these warnings

12 warnings:
  unknown variable/constant "{_SearchFor}" detected, ignoring (RegistrySearchBackup.nsh:54)
  unknown variable/constant "{_SearchFor}" detected, ignoring (RegistrySearchBackup.nsh:56)
  unknown variable/constant "{_Type}" detected, ignoring (RegistrySearchBackup.nsh:59)
  unknown variable/constant "{_SearchKeys}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_SearchValues}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_SearchStrings}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_SearchTerm}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_Type}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_SubKeys}" detected, ignoring (macro:registry::Open:1)
  unknown variable/constant "{_ResultValueOrKey}" detected, ignoring (macro:registry::SaveKey:1)
  unknown variable/constant "{_FileName}" detected, ignoring (macro:registry::SaveKey:1)
  unknown variable/constant "{_ResultPath}" detected, ignoring (macro:registry::SaveKey:1)

and of course it doesn't work when these variables are ignored.

Here's the macro and the function where the error occures:

!include "Registry.nsh"

Function _BackupRegistrySearch

	Var /GLOBAL _RegPath
	Var /GLOBAL _SearchKeys
	Var /GLOBAL _SearchValues
	Var /GLOBAL _SearchStrings
	Var /GLOBAL _SearchFor
	Var /GLOBAL _CaseSens
	Var /GLOBAL _Type
	Var /GLOBAL _SubKeys
	Var /GLOBAL _FileName
	Var /GLOBAL _Handle
	
	Var /GLOBAL _SearchTerm
	
	Var /GLOBAL _ResultPath
	Var /GLOBAL _ResultValueOrKey
	Var /GLOBAL _ResultString
	Var /GLOBAL _ResultType
	Var /GLOBAL _FoundItemNumber
	
	Pop $_FileName
	Pop $_SubKeys
	Pop $_Type
	Pop $_CaseSens
	Pop $_SearchFor
	Pop $_SearchStrings
	Pop $_SearchValues
	Pop $_SearchKeys
	Pop $_RegPath
	
	;	Exch $_FileName
	;	Exch 1
	;	Exch $_SubKeys
	;	Exch 2
	;	Exch $_Type
	;	Exch 3
	;	Exch $_CaseSens
	;	Exch 4
	;	Exch $_SearchFor
	;	Exch 5
	;	Exch $_SearchStrings
	;	Exch 6
	;	Exch $_SearchValues
	;	Exch 7
	;	Exch $_SearchKeys
	;	Exch 8
	;	Exch $_RegPath
	
	StrCmp $_CaseSens 0 _NotCaseSensitive _CaseSensitive
	_NotCaseSensitive:
		StrCpy $_SearchTerm "/NI=${_SearchFor}"
	_CaseSensitive:
		StrCpy $_SearchTerm "/NS=${_SearchFor}"
		
	StrCmp $_Type "" _StartSearch 0
		StrCpy $_Type "/T=${_Type}"
	
	_StartSearch:
		${registry::Open} "$_RegPath" "/K=${_SearchKeys} /V=${_SearchValues} /S=${_SearchStrings} ${_SearchTerm} ${_Type} /G=${_SubKeys} /B=0" $_Handle
		StrCmp $_Handle 0 _Error 0
		
	_SearchLoop:
	
		${registry::Find} "${_Handle}" $_ResultPath $_ResultValueOrKey $_ResultString $_ResultType
		StrCmp $_ResultType "" _End 0
		StrCmp $_ResultType "REG_KEY" _BackupRegKey _BackupRegValue
		
		_BackupRegValue:
			${registry::SaveKey} "${_ResultPath}" "${_FileName}" "/A=1 /N='${_ResultValueOrKey}' /G=0" $0
			StrCmp $0 -1 _Error 0
			IntOp $_FoundItemNumber $_FoundItemNumber + 1
			
		_BackupRegKey:
			${registry::SaveKey} "${_ResultPath}\${_ResultValueOrKey}" "${_FileName}" "/A=1" $0
			StrCmp $0 -1 _Error 0
			IntOp $_FoundItemNumber $_FoundItemNumber + 1
	
		Goto _SearchLoop
	
	_Error:
		Push -1
		Return
	
	_End:
		Push $_FoundItemNumber
		Return
	
FunctionEnd

!macro BackupRegistrySearch RegPath SearchKeys SearchValues SearchStrings SearchFor CaseSens Type SubKeys FileName

	Push "${RegPath}"
	Push "${SearchKeys}"
	Push "${SearchValues}"
	Push "${SearchStrings}"
	Push "${SearchFor}"
	Push "${CaseSens}"
	Push "${Type}"
	Push "${SubKeys}"
	Push "${FileName}"
	
	Call _BackupRegistrySearch
  
!macroend

and here how I embedded it into the application:

!include "RegistrySearchBackup.nsh"
	
!insertmacro "BackupRegistrySearch" "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 1 0 0 "Steam App" 1 "" 0 "TestBackup.reg"

Does anybody here have an idea what the problem is?
Thanks for your help Wink

Mark Sikkema
Offline
Last seen: 12 years 7 months ago
Developer
Joined: 2009-07-20 14:55
Your variables are not right

Why are you using

StrCpy $_SearchTerm "/NI=${_SearchFor}"

Probably it should be:

StrCpy $_SearchTerm "/NI=$_SearchFor"

and so on for the other variables !

The ${...}, is meant just for constants or as parameters within macros.
Example:

!define PORTABLEAPPNAME "Winamp Portable"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"

!macro ReplaceInFileCS SOURCE_FILE SEARCH_TEXT REPLACEMENT
	Push `/S=1`
	Push `${SOURCE_FILE}`
	Push `${SEARCH_TEXT}`
	Push `${REPLACEMENT}`
	Call ReplaceInFile
!macroend

Formerly Gringoloco
Windows XP Pro sp3 x32

Benedikt93
Offline
Last seen: 9 years 4 months ago
Joined: 2009-12-17 14:46
Thx

Thanks Smile

"Der Klügere gibt nach, deshalb regieren Dumme die Welt."

Bruce Pascoe
Offline
Last seen: 12 years 3 months ago
Joined: 2006-01-15 16:14
NSIS

NSIS's syntax is just weird. The ${} thing always confused me too (and still does).

Log in or register to post comments