ilovetechno
(Fresh Scripter)
2004-11-17 12:34 PM
[INI] Copy complete section to other INI file

I want to make a script that copy's a complete section to another INI file.

Sample file:
Code:

[SnapwareServerInterface]
NetworkAddress=snapware4.1
Port=5007
Last DownTime=1100199726
SrvDlgLoginTimeout=30
[Stream Information]
LoginName=325
UsersDevice=325
AllowToSavePassword=NO
LoginPassword=
AdsLogin=NO
OpenStreamTimeOut=3000
SnapshotOnConnectionCleared=YES
StreamType=CSTA
[Program]
SnapwarePath=C:\Program Files\Snapware\
[SnapIn Manager]
SnapInName1=
SnapInCommand1=
SnapInState1=
SnapInVisible1=0
[MainWindow]
StatusWndXPos=151
StatusWndYPos=208
Width=742
Height=519
ListSplitter=177



the target file does contain the same section. The script must overide that whole secion.

I have search the whole forum but couldn't find anything...

I tried readprofilestring but i cant copy a whole section.


Who can help me


Richard H.Administrator
(KiX Supporter)
2004-11-17 01:54 PM
Re: [INI] Copy complete section to other INI file

Code:
$sSourceINI=".\x.ini"
$sSourceSection="SOURCE"
$sDestINI=".\y.ini"
$sDestSection="DEST"

; First, delete the destination section
$=WriteProfileString($sDestIni,$sDestSection,"","")
; Now, copy the section over from the source
For Each $sKey In Split(ReadProfileString($sSourceINI,$sSourceSection,""),Chr(10))
If $sKey
$=WriteProfileString($sDestINI,$sDestSection,$sKey,
ReadProfileString($sSourceINI,$sSourceSection,$sKey)
)
EndIf
Next
Exit 0



ilovetechno
(Fresh Scripter)
2004-11-17 04:02 PM
Re: [INI] Copy complete section to other INI file

Thank you.. it works!!


LonkeroAdministrator
(KiX Master Guru)
2004-11-17 04:08 PM
Re: [INI] Copy complete section to other INI file

sure it does

ilovetechno
(Fresh Scripter)
2004-11-24 11:27 AM
Re: [INI] Copy complete section to other INI file

The story continous...

The INI file is exported by Kixstart from the registry. If I export you see the following:



If I open the file in write.exe I see the same INI in a right formatted way.



If I export two files from the registry and I want to copy a section to another section and write it back to the registry.. How do I that. Whit the script above i can not copy from/to an unformatted INI file.

The one who can give me a solution wil get a Gmail account in return..




JochenAdministrator
(KiX Supporter)
2004-11-24 11:57 AM
Re: [INI] Copy complete section to other INI file

Show us HOW you export the registry thing by KiXtart and we may modify it to export proper format

LonkeroAdministrator
(KiX Master Guru)
2004-11-24 12:00 PM
Re: [INI] Copy complete section to other INI file

eh...
it seems to me the ini-file is just fine.
what is that kladblock-proggie you are using?
looks like notepad...

anyways, that "ini-file is exported by kixtart from registry"...
could you show that code?
kixtart does not do it autom. so you have some sorta script there, right?


JochenAdministrator
(KiX Supporter)
2004-11-24 12:23 PM
Re: [INI] Copy complete section to other INI file

Kladblok is notepad.

I foresee an Issue with chr(13)+chr(10), chr(10)+chr(13), chr(13), chr(10) ... any of these combinations..


ilovetechno
(Fresh Scripter)
2004-11-24 12:26 PM
Re: [INI] Copy complete section to other INI file

Quote:

Show us HOW you export the registry thing by KiXtart and we may modify it to export proper format




$Rows = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Telesnap\SwAdmin\User-List\302\Config-Group", "SnapwareIni")
IF Open( 3 , "c:\export.TXT" , 5 ) = 0
If @ERROR = 0
$Rows = WriteLine( 3 , "$Rows + Chr(13) + Chr(10) )
Endif


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 12:36 PM
Re: [INI] Copy complete section to other INI file

hmm...
so, you say that you only read 1 registry value which has the whole ini-structure in it?


ilovetechno
(Fresh Scripter)
2004-11-24 12:41 PM
Re: [INI] Copy complete section to other INI file

Yes.

And I have to copy a section from that INI file to another INI file in the registry


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 12:44 PM
Re: [INI] Copy complete section to other INI file

so, you should try this:
Code:

$Rows = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Telesnap\SwAdmin\User-List\302\Config-Group", "SnapwareIni")
IF Open( 3 , "c:\export.TXT" , 5 ) = 0
$Rows = WriteLine( 3 , join(split($Rows,chr(10)),@crlf))
Endif



you need at least kix version 4.10 for this to worky...


ilovetechno
(Fresh Scripter)
2004-11-24 02:08 PM
Re: [INI] Copy complete section to other INI file

Oke this works...

The only thing i need to do is write the INI file back to the registry. I tried this one but it isn't working

$array=ReadFile('.\export.txt')

Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=chr(10)
$f=freefilehandle
$_=open($f,$file)
if @error exit @error endif
do $t=$t+$lf+readline($f) until @error
$_=close($f)
$ReadFile=split(substr($t,2),$lf)
EndFunction

Function regwrite($subkey,$value,$data,optional $type)
DIM $keyarray,$keypath,$loop,$rc

if readvalue($subkey, $entry) <> $expression
if not $type
$type=readtype($subkey, $entry)
if @error
$type="REG_SZ"
endif
endif
$keyarray=split("$key","\")
for $loop=0 to ubound($keyarray)
$keypath=$keypath+$keyarray[$loop]+"\"
if not KEYEXIST("$keypath") $rc=addkey("$keypath") endif
next
if KEYEXIST("$key")
$rc=writevalue("$subkey","$value","$data",$type)
else
exit @error
endif
endif
ENDFUNCTION


Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\Telesnap\SwAdmin\User-List\342\Config-Group","SnapwareIni",$array)




JochenAdministrator
(KiX Supporter)
2004-11-24 02:20 PM
Re: [INI] Copy complete section to other INI file

Question:

Why using writeline() to write to an ini file ?
Is there anything speaking against using writeprofilestring(), which of course generates valid format ?

Furthermore, is this registry key exported and imported during the same kixtart script run ?


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 02:30 PM
Re: [INI] Copy complete section to other INI file

his ini-write is because he has some weird registry value including THE WHOLE ini-file.
thus there is no reasoning writing each ini-value separately when you can do it all in one writeline.

then, removing all the not-needed sections, writeprofilestring() should be used to trash the not-wanted sections.
after that, readfile() udf can be used to read the whole file back with the correct chr(10) separated format.


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 02:56 PM
Re: [INI] Copy complete section to other INI file

k, checked the code and can easily say, you have no use for that regwrite() udf.

now, I want to once more ask, as this type of stuff I have never seen...
is it really so that you have A SINGLE registry value that holds the whole data?
all the ini-values and stuff?
and that you want to write the stuff back to A SINGLE value?
if yes, then nothing.
this way it actually is really easy.

but if not, please tell as the big picture is something we need to see.


ilovetechno
(Fresh Scripter)
2004-11-24 03:06 PM
Re: [INI] Copy complete section to other INI file

We use a phone program for our CTI/PABX called Snapware.

This program stores user configurations to the registry in one key. I have to edit that registry once a week when preforming a update. So i want it scripted..

But i have not figured out how. I can produce the right INI file now but I have to write it back...


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 03:21 PM
Re: [INI] Copy complete section to other INI file

why you need the ini?
can't you just update the registry-values directly?


Richard H.Administrator
(KiX Supporter)
2004-11-24 04:17 PM
Re: [INI] Copy complete section to other INI file

Quote:

can't you just update the registry-values directly?



He could, however this started way back as a "how do I copy one ini file section to another".

In this case it is probably easier to perserve the intermediate temporary INI files for managing the data, rather than write a special handler for "ini files in registry values"


LonkeroAdministrator
(KiX Master Guru)
2004-11-24 05:40 PM
Re: [INI] Copy complete section to other INI file

hmm...
I think it could be easiest to finally find out the whole picture.
even though, without it he can get it working as he wants.