pgpatron
20th February 2004 09:36 UTC
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
pgpatron
20th February 2004 17:37 UTC
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,
Anders
20th February 2004 17:40 UTC
why cant you use the registry functions in nsis?
pgpatron
20th February 2004 18:01 UTC
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.
MarcoDeGroot
27th February 2004 16:36 UTC
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
Joost Verburg
27th February 2004 16:38 UTC
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.