#129680 - 2004-11-17 12:34 PM
[INI] Copy complete section to other INI file
|
ilovetechno
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
Registered: 2000-01-24
Posts: 4946
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
Fresh Scripter
Registered: 2004-11-17
Posts: 13
|
Thank you.. it works!!
|
Top
|
|
|
|
#129684 - 2004-11-24 11:27 AM
Re: [INI] Copy complete section to other INI file
|
ilovetechno
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
|
|
|
|
#129688 - 2004-11-24 12:26 PM
Re: [INI] Copy complete section to other INI file
|
ilovetechno
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
|
|
|
|
#129690 - 2004-11-24 12:41 PM
Re: [INI] Copy complete section to other INI file
|
ilovetechno
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
|
|
|
|
#129692 - 2004-11-24 02:08 PM
Re: [INI] Copy complete section to other INI file
|
ilovetechno
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
|
|
|
|
#129696 - 2004-11-24 03:06 PM
Re: [INI] Copy complete section to other INI file
|
ilovetechno
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
|
|
|
|
#129698 - 2004-11-24 04:17 PM
Re: [INI] Copy complete section to other INI file
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|