Eventually I have decided to follow the advice to write C# code to manage the config file.
So I wrote a .dll in C# and then I used it as ReserveFile in my NSIS script, using CLR NSIS (
http://nsis.sourceforge.net/Call_.NET_DLL_methods_plug-in[
^]) plug-in which allows to call methods in a managed .NET DLL.
So I wrote a function in the NSIS script with the subsequent code:
Function WriteConfig
InitPluginsDir
SetOutPath "${NSISDIR}\Plugins\"
File "${NSISDIR}\Plugins\MyNETdll.dll"
CLR::Call /NOUNLOAD "MyNETdll.dll" "Namespace.Class" "Method-To-Write_in-Config" 3 "Config path" "Key" "Value"
CLR::Destroy
FunctionEnd
where "3" is the number of parameters that the method accepts and the subsequent strings are the parameters themselves.
In this way, whatever method written in C# can be called from the NSIS script!