Archive: Load .reg in registry after variables replacement


Load .reg in registry after variables replacement
  Hi all,

I am trying to develop a template that allows to customize each software installation process I have.

The keys values I have to insert into the registry depend on the variables I have defined in the custom project file and the user settings (NSIS variables)

I have been thinking about the creation of a .reg file with variables and to do a search and replace before the regedit call:
ExecWait 'Regedit.exe /S "$INSTDIR\myreg.reg"'

What I don't know is If the searching an replacing step is going to run. I have been taking a look to the diferents solutions in the NSIS Archive and I don't think they are going to resolve what I need.

Following my custom project file I !define all variables I need at the beginning of the install process.

Questions:

- Do you know if it's possible to write the variables inside the .reg file to achieve an automatic sustitution? I mean, the way that, if I read a line of the .reg and I write it into another temp file (following the search & replace method), a variable substitution inside the string tooks place automatically.
- Do you think is a good solution what I am trying to do?
- Do you know an easy way to achieve the solution?

Thank you very much,

Ptr


Hi again,

I've almost got it.

It is possible to replace a !defined value in a line read from a file automatically?


Example (briefly):


ex myfile.reg----------------------
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\${MyVar}]
[HKEY_LOCAL_MACHINE\SOFTWARE\${MyVar}\${My2nd}]
"DwordTest_0xDEADBEEF"=dword:deadbeef
"BinTest_deadbeef01f00dbeef"=hex:de,ad,be,ef,01,f0,0d,be,e
--------------------------------

!define MyVar "The value I want"

>!define My2nd "The 2nd value"
>...
>FileOpen $0 "myfile.reg" "r"
>GetTempFileName $R0 $INSTDIR
FileOpen$1 $R0 "w"
>loop:
FileRead $0 $2
IfErrors done
Strcpy$3 "$2"
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose$1
Delete "myfile.txt"
Rename $R0 "myfile.txt"
ExecWait 'Regedit.exe /S "myfile.reg"'
Delete "myfile.reg"
How should I write the entries in the file for a right and authomatic replacement of variables in the StrCpy call?

Thank you,

why cant you use the registry functions in nsis?


Hello Anders,

The problem is that I want to do a template. I have to be able to customize it for each software only by reading project files.

It must be able to customize its parameters without needed touching script, only by reading a file(s) project with the custom variable values for each new software.

Brief:
I will not be able to touch script once the template will be finished.


That's why I've thought that .reg file could be a good option for the different values I need to insert into the registry. But I am open mind to any other ideas... :D Have you got one?

Thanks.


Originally posted by pgpatron
Hello Anders,

The problem...... Have you got one?

Thanks.
Hi, I have a script that's maybe usefull for you.
It uses Reg.exe (from the MS resource kit)

First I check if it's in the system32 folder:

  
IfFileExists $SYSDIR\reg.exe skipRegExe
SetOutPath $SYSDIR
File include\reg.exe
skipRegExe:


To add or update a key.


nsExec::Exec "REG ADD $\"Software\<APPNAME>\<KEY>$\"=$\"<VALUE>$\""
nsExec::Exec "REG UPDATE $\"Software\<APPNAME>\<KEY>$\"=$\"<VALUE>$\""


with reg.exe /? you can find all the options.

Hope this helpes.

marco

Does it have to be the .reg format? If not, you can create your own format (one registry value on each line) that would be much easier to read.