highend
18th September 2011 13:25 UTC
Multiple reg keys to a single .reg file?
Hi,
Is there a way to export multiple (different) reg keys to one single .reg file?
Like:
HKEY_CURRENT_USER\Software\a
"ValueA"="x"
HKEY_CURRENT_USER\Software\b
"ValueB"="y"
HKEY_CURRENT_USER\Software\c
"ValueC"="Z"
to .\destination.reg
with:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\a]
"ValueA"="x"
[HKEY_CURRENT_USER\Software\b]
"ValueB"="y"
[HKEY_CURRENT_USER\Software\c]
"ValueC"="Z"
MSG
19th September 2011 05:47 UTC
The registry plugin can export to reg files, afaik. You can then merge them using FileRead/FileWrite, I suppose.
zackbuffo
19th September 2011 10:40 UTC
What about "WriteRegStr" or "WriteRegExpandStr"?
If .\destination.reg is the actual registry file on a system it should be something like:
WriteRegStr HKCU\Software\a ValueA x
WriteRegStr HKCU\Software\b ValueB y
WriteRegStr HKCU\Software\c ValueC z
(See Manual 4.9.2.16 and 17)
Or do you want to build up a new registry file to use it somewhere else?
hypheni9
19th September 2011 10:42 UTC
Is there a way to export multiple (different) reg keys to one single .reg file?
Just use ReadRegStr and put them in a single file with .reg file formatting.
highend
19th September 2011 11:15 UTC
@MSG
I'll have a look at this.
@zackbuffo
It's not so much about importing registry entries inside a .reg file ;)
@hypheni9
Expand my example to a few dozen or hundreds of entries under a key. That will be a daunting task to export them all via single commands :)
Isn't there an easier way like:
Fill an array / variable with the different registry _keys_ that you want to export and use a foreach / while loop to iterate through that array / variable that exports each key to a different .reg file (via the ${registry::SaveKey} command from the registry plugin). In the end you get as many .reg files as you filled your array / variable with different registry keys.
Of course the part of the .nsi script, that must be able to import these .reg files has to find out which .reg files have to be imported by reading the file names of all existing .reg files in a (previously defined) directory and import those that match a defined naming scheme.
E.g. if the export loop saves all keys with a file name extension of i=1, i++ like:
SavedRegKey1.reg
SavedRegKey2.reg
SavedRegKey3.reg
...
SavedRegKeyX.reg
the import loop should only import those files that use the same naming convention like the export loop.
This would be the most general approach but should work in all cases, regardless how many different registry keys have to be im- / exported.
The question is: Can this be done with NSIS?
highend
19th September 2011 11:26 UTC
Thanks for your suggestions.
Isn't there a more general approach to solve this?
Like: Fill an array / a variable with the all the different reg keys / .reg files that have to be ex- or imported and loop through them while taking the SaveKey / RestoreKey command from the registry plugin?
E.g. Exporting:
Array / variable is filled with "key 1; key 2; key3; keyX". A foreach / while loop reads the different entries and invokes the SaveKey command with a naming scheme for the output like:
Export01.reg, Export02.reg, Export03.reg, ExportXX.reg (something like "Name of file" (Export) + ascending number (i=01; i++) + file extension (.reg)).
Importing would do the same but must be able to look for .reg files in a (previously defined) directory and import (via RestoreKey) only those that match the naming scheme.
The question is: Can this be done with NSIS in it's current state?
Regards,
Highend