Archive: registry::SaveValue ?


registry::SaveValue ?
I could find registry::SaveKey in the Registry NSIS plugin
(by Instructor), but I couldn't find a registry::SaveValue.

Is there a plugin or a function that achieves this level of granularity?

That is, saving a .REG that contains only a desire value in a registry key, not all values in that key.

Is there such a plugin/function?

Thanks!


Just read the documentation that comes with the plugin. ({registry::Write})

Or, search the NSIS help for WriteRegStr, WriteRegBin, WriteRegDWORD, etc.


If you really want to save it as a .REG file, first read the value the normal way, then create the .REG file with FileOpen,FileWrite and FileClose


Originally posted by Comperio
Just read the documentation that comes with the plugin. ({registry::Write})

Or, search the NSIS help for WriteRegStr, WriteRegBin, WriteRegDWORD, etc.
These write into the registry. I want to read from the registry and write to a file (REGEDIT4 format).


Originally posted by Anders
If you really want to save it as a .REG file, first read the value the normal way, then create the .REG file with FileOpen,FileWrite and FileClose
Yes, that is exactly what I meant. I was hoping that there is a single line statement like ${registry::SaveKey} that does that but it seems there is no escape of having to write something more elaborate.

I am thinking of perhaps adding this function to the Registry plugin 3.5. However, I have never written an NSIS plugin, so it may take me some time to learn how to do this.

It seems that a crude (ugly) hack that would implement this is to simply copy the function _SaveKey() in registry.c, rename it to _SaveValue, then add an if statement at line 948 to make RegWriteType conditional upon matching the value name.

Any other tips are welcome.

BTW, which compiler is recommended for producing the DLL (i.e. without having to require the VC6, VC2005 or VC2008 redistributable)?

From nsnb
I want to read from the registry and write to a file (REGEDIT4 format)
Sorry, I misunderstood your question earlier.

If you didn't want to modify the registry plugin code itself, you could just create your own registry header file by wrapping the registry read and create file functions into a macro and then creating a !define named "registry::SaveValue". If you put all this into your own header file, then you can include your header in lieu of the registry header.

example:
##add this just to ensure your header doesn't get added more than once
!fndef myRegistryHeader

!define registry::SaveValue "!insertmacro Registry::SaveValue _param1 _param2 _param3"

!macro Registry::SaveValue _param1 _param2 _param3
; may have to add parameters here
; see Registry.nsh to see how macros are structured

; ...
; [add registry code here]
; ...
!macroend

!endif


In your macro, use the code from the registry plugin. Then, in your script, just include your new registry header instead of the default "Registry.nsh"

Comperio, thanks for this tip. If I fail to modify the plugin itself, I will certainly go this route (I am a little more confident authoring new code using NSIS rather than hack somebody else's code in C).


Time to give back to this great community. :)

Attached please find my hack for the Registry Plugin which implements the functionality after which I sought in my original message.

Basically, all what I did was copying verbatim the function SaveKey (in registry.c), renaming the copy to SaveValue, then modifying the line:

RegWriteType(hFileWrite, szValue, dwType, szString, dwSizeString);
to:
if ( !lstrcmpi(szValue, szValueAsked) )
RegWriteType(hFileWrite, szValue, dwType, szString, dwSizeString);
szValueAsked is defined as global in the beginning of registry.c:
char szValueAsked[MAX_PATHLEN];
Also, right at the beginning of the function I added (in the right order):
popstring(szValueAsked, NSIS_MAX_STRLEN); /* name of single value to be saved */
This essentially creates a new registry.dll (attached) that contains ${registry::SaveValue} with the calling parameters as described in the attached readme.txt. Attached also find the corresponding registry.nsh.

I am sure that the original author of this package can do much better job than I did, but I needed this quickly so I implemented it in the most "quick & dirty" manner.

Fantastic!
This is just what I was looking for in that plugin!