Archive: I'd like to export .reg files with NSIS


I'd like to export .reg files with NSIS
I am in need of a function which creates REG files from a branch with all sub-branches, like exporting using regedit.exe.

And another to import them (althought it can be
done with "Exec "REGEDIT.EXE /S FILE.REG"".


To delete whole branches is easy with this trick:

import this:

REGEDIT4

[-HKEY_CURRENT_USER\Software\Microsoft]


I hope some NSIS developer listen to my pray :)


Exporting .reg files...
Is possible but quite complicated in NSIS. Search trees in the registry is not the favorite thing I would do... Isn't this possible using regedit itself? Or search the internet for some small utility that will do this job. I'm sure someone already programmed it...

Good luck,
-Hendri.


Re: I'd like to export .reg files with NSIS

Originally posted by n0On3
I am in need of a function which creates REG files from a branch with all sub-branches, like exporting using regedit.exe.

And another to import them (althought it can be
done with "Exec "REGEDIT.EXE /S FILE.REG"".


To delete whole branches is easy with this trick:

import this:

REGEDIT4

[-HKEY_CURRENT_USER\Software\Microsoft]


I hope some NSIS developer listen to my pray :)
It's staring you right in the face...

ExecShell "" FILE.REG

Since the .reg file is file associated in the registry to open with regedit, it will try to import the file. It will prompt you for this, you click Yes, it imports the data in the file to the registry (provided you have the proper permissions, of course).

For deleting the branch, though, I wouldn't try using the method you mentioned above. You should just use DeleteRegKey, that's what it's there for.

for Pomflain, I didn't know that DeleteRegKey exist, and now I find surprising that NSIS can delete whole branches and can not save them. Anyway, I just wanted to explicit what functions could be added in NSIS regarding the registry, the purpose of the message is to add ExportRegKey as a function :D

==================

for Smile2Me, before coming here and post the idea I found another program to export from registry -and this is how I am working now- but it's slow, big and not very versatile.

After working with that program for one or two months I decided to post this idea in this forum because I think it's worth the implementation.

Considering the enormous possibilites of NSIS, and that is already working with the Registry I thought it wouldn't be that difficult to implement and would provide more functionality to *the* installation program :cool:


My advise: Write a small dll that does the job. It's possible in NSIS but really tricky with a lot of if structures. That simply works better in Delphi/C++

-Hendri.


Originally posted by n0On3
for Pomflain, I didn't know that DeleteRegKey exist, and now I find surprising that NSIS can delete whole branches and can not save them. Anyway, I just wanted to explicit what functions could be added in NSIS regarding the registry, the purpose of the message is to add ExportRegKey as a function :D
Well essentially the registry functions are just wrappers for the WIN32 API registry calls. I.E. ReadRegX -> RegOpenKeyEx -> RegQueryValueEx. So as far as a DeleteRegKey, there isn't one. The way you delete a registry tree is the following. You call RegEnumKey and RegEnumValue (EnumRegKey and EnumRegValue in NSIS) to enumerate over the keys in the tree and then RegDeleteValue and RegDeleteKey (DeleteRegValue and DeleteRegKey in NSIS). So you could do the exact same thing in NSIS, exact same programmatically. If you REALLY wanted to have a function to import values from a file, RegLoadKey can do it, but it's limited to creating values in HKEY_USERS or HKEY_LOCAL_MACHINE, no ROOT.

So now back to the original issue. For importing, I'd just do like I said about the ShellExecute of regedit to import the file. If that isn't a viable option and you are importing into HKU or HKLM then you can write a wrapper for RegLoad to import that file.

If you are still having trouble with things and these solutions don't work, I can write you up some .nsi or C code for the source to make these things work, they really aren't as complicated as they might seem.

Originally posted by Pomflain


So as far as a DeleteRegKey, there isn't one.


If you REALLY wanted to have a function to import values from a file, RegLoadKey can do it, but it's limited to creating values in HKEY_USERS or HKEY_LOCAL_MACHINE, no ROOT.

So now back to the original issue. For importing,


I don't understand you. In the first sentence, are you saying that there's no DeleteRegKey? because, of course, there is, at least in v1.96. If you didn't say that I didn't understand a thing.


Well, I don't "REALLY wanted to have a function to import values from a file". What I miss in NSIS is a function to EXPORT to a regfile (you can read this in the thread title). In my first post you can read the command I am using to import: 'Exec "REGEDIT.EXE /S FILE.REG"'
and it works, so what I need is to export.

As mentioned earlier, it's possible to write some script or function that reads trees of the registry and generates code similar to what regedit produces when exporting to .reg. But actually, this is quite messy in NSIS, because you will need a lot of loops, labels and StrCmp's. So either use the program you were already using or search for some source or program it yourself into a dll file.

[Edit]
http://www.google.nl/search?hl=nl&q=...istry+code&lr= might be helpfull.
[/Edit]

Good luck,
-Hendri.


Sorry
Yeah I meant importing a key, not deleting. I typed the wrong thing. Like I said it's really not all that complicated and doesn't require a whole bunch of loops. I already have a script that does something similar, but it doesn't export to a .reg file, it backs up a registry tree so that it can then be restored back to its original state if the program is uninstalled. If you want me to write you up some NSI scripting code or write you win32 to put into a custome installer or dll, all you have to do is ask.


for Pomflain,

I'd be glad to use your script which backs up and restores registry tree.

I am using NSIS to run another program which makes use of the registry. I use this program on several computers from a CompactFlash drive, and the program makes changes in the registry every time it runs; so I need to import the regfile, run the program, and on exit save the registry tree.

The thing is that the program I am using now is very bogus and sometimes forgets data.

See you next time :)


Quote:


I think that a DLL would be faster.



Originally posted by Smile2Me
As mentioned earlier, it's possible to write some script or function that reads trees of the registry and generates code similar to what regedit produces when exporting to .reg. But actually, this is quite messy in NSIS, because you will need a lot of loops, labels and StrCmp's. So either use the program you were already using or search for some source or program it yourself into a dll file.

Good luck,
-Hendri.
what's faster, the source/dll option, or the NSIS' loops?

Anyway, I think it's messier to use to programs for just one work. :D