Page 1 of 1 1
Topic Options
#129680 - 2004-11-17 12:34 PM [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
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

Top
#129681 - 2004-11-17 01:54 PM Re: [INI] Copy complete section to other INI file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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


Top
#129682 - 2004-11-17 04:02 PM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
Thank you.. it works!!

Top
#129683 - 2004-11-17 04:08 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
sure it does
_________________________
!

download KiXnet

Top
#129684 - 2004-11-24 11:27 AM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
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..



Top
#129685 - 2004-11-24 11:57 AM Re: [INI] Copy complete section to other INI file
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6372
Loc: Stuttgart, Germany
Show us HOW you export the registry thing by KiXtart and we may modify it to export proper format
_________________________



Top
#129686 - 2004-11-24 12:00 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
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?
_________________________
!

download KiXnet

Top
#129687 - 2004-11-24 12:23 PM Re: [INI] Copy complete section to other INI file
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6372
Loc: Stuttgart, Germany
Kladblok is notepad.

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



Top
#129688 - 2004-11-24 12:26 PM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
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

Top
#129689 - 2004-11-24 12:36 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
hmm...
so, you say that you only read 1 registry value which has the whole ini-structure in it?
_________________________
!

download KiXnet

Top
#129690 - 2004-11-24 12:41 PM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
Yes.

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

Top
#129691 - 2004-11-24 12:44 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
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...
_________________________
!

download KiXnet

Top
#129692 - 2004-11-24 02:08 PM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
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)



Top
#129693 - 2004-11-24 02:20 PM Re: [INI] Copy complete section to other INI file
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6372
Loc: Stuttgart, Germany
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 ?


Edited by Jochen (2004-11-24 02:22 PM)
_________________________



Top
#129694 - 2004-11-24 02:30 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
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.
_________________________
!

download KiXnet

Top
#129695 - 2004-11-24 02:56 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
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.
_________________________
!

download KiXnet

Top
#129696 - 2004-11-24 03:06 PM Re: [INI] Copy complete section to other INI file
ilovetechno Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 13
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...

Top
#129697 - 2004-11-24 03:21 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
why you need the ini?
can't you just update the registry-values directly?
_________________________
!

download KiXnet

Top
#129698 - 2004-11-24 04:17 PM Re: [INI] Copy complete section to other INI file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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"

Top
#129699 - 2004-11-24 05:40 PM Re: [INI] Copy complete section to other INI file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
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.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 35 anonymous users online.
Newest Members
thequeen, ameliaryan, shalomsalami, dkdssdk, Vroon
17639 Registered Users

Generated in 0.06 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org