Page 1 of 1 1
Topic Options
#190655 - 2008-11-19 03:01 PM Change string in ini file without a index
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hello

I want to change a string value in a ini file .
In the ini file there is no index like [server] or so .
I want to change the string in the middle of a lang string
example : I want to change the bold string to ICO=Mydomain

FAVOURITES MyFavouritesCompany10=20348721<element_attr>Purchase orders<element_attr>*FAVOURITES<element_attr>0<element_attr>functionStringToObject:<element_attr>functionToString:<element_attr>start<element_attr>PurchaseOrderEnquiry<element_attr>
Navifunction.bmp<element_attr>Y<element_attr><element>*FAVO_OBJECTS<element_attr>Business objects<element_attr>*FAVOURITES<element_attr>100<element_attr>emptyStringToObject:<element_attr>undefinedObjectToString:<element_attr><element_attr><element_attr>
Navifolder_blue.bmp<element_attr>Y<element_attr><element>*FAVO_FUNCTIONS<element_attr>Functions<element_attr>*FAVOURITES<element_attr>100<element_attr>emptyStringToObject:<element_attr>undefinedObjectToString:<element_attr><element_attr><element_attr>
Navifolder_blue.bmp<element_attr>Y<element_attr><element>
FAVOURITES MyFavouritesCompanyP2=*FAVO_OBJECTS<element_attr>Business objects<element_attr>*FAVOURITES<element_attr>100<element_attr>emptyStringToObject:<element_attr>undefinedObjectToString:<element_attr><element_attr><element_attr>
Navifolder_blue.bmp<element_attr>Y<element_attr><element>*FAVO_FUNCTIONS<element_attr>Functions<element_attr>*FAVOURITES<element_attr>100<element_attr>emptyStringToObject:<element_attr>undefinedObjectToString:<element_attr><element_attr><element_attr>
Navifolder_blue.bmp<element_attr>Y<element_attr><element>
FILES_DEFAULT numberOfLocalRecordsForAdditionalFile=100
HOSTCONN AS/400CONNECTION ICOZZVD ICO=10.32.62.30<sep>ICO<sep>tcpip<sep>A600AP,A600DP,BE600DP,ZBE600DP<sep>N<sep>Y<sep>SAVELS<sep>987680 851943 987840 1024967 901550 592848 654656 <sep><sep>ICO600D<sep>
HOSTCONN DefaultASWStartUpLibraries=A600AP

Could someone help me out how to change the value ICO .

Thanks


Edited by Lonkero (2008-11-20 06:23 PM)

Top
#190656 - 2008-11-19 03:50 PM Re: Change string in ini file without a index [Re: Shajoca]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Hmmm good one, here's one approach, assuming there is only 1 times "ICO=" in the ini file. Also it is untested so copy your ini file, I just wrote this out of the top of my head.

 Code:
Dim $objFSO, $strIni, $objIni, $strTxt, $arrTxt, $strItm, $strItm2, $strIP
$objFSO = CreateObject("Scripting.FileSystemObject")
$strIni = "C:\someinifile.txt"
$strIP = "10.33.10.1"
$objIni = $objFSO.OpenTextFile($strIni, 1)
$strTxt = $objIni.ReadAll
$objIni.Close
$arrTxt = Split($strTxt,@CRLF)
For Each $strItm in $arrTxt
  If Left($strItm,4) = "ICO="
    $strItm2 = Split($strItm, "<")
    ? "IP: "+$strItm2[0]
    $strItm2[0] = $strIP
    $strItm = Join($strItm2, "<")
  EndIf
Next
$strTxt = Join($arrTxt,@CRLF)
$objIni = $objFSO.OpenTextFile($strIni, 8, 1)
$objIni.Write($strTxt)
$objIni.Close

Top
#190657 - 2008-11-19 03:52 PM Re: Change string in ini file without a index [Re: Arend_]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
thanks , I gonne test right away .
Top
#190658 - 2008-11-19 04:07 PM Re: Change string in ini file without a index [Re: Arend_]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hmmm ... the whole part between

$objIni.Close

and

$objIni.Write($strTxt)

can be replaced by a simple:

 Code:
$strTxt = join(split($strTxt,"ICO=10.32.62.30"),"ICO=Mydomain")


so much for golfing ;\)
_________________________



Top
#190659 - 2008-11-19 04:13 PM Re: Change string in ini file without a index [Re: Jochen]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hi could you a Little clear out please the following variables
Dim $objFSO, $strIni, $objIni, $strTxt, $arrTxt, $strItm, $strItm2, $strIP
$objFSO = CreateObject("Scripting.FileSystemObject")
$strIni = "C:\someinifile.txt"
$strIP = "10.33.10.1"
$objIni = $objFSO.OpenTextFile($strIni, 1)
$strTxt = $objIni.ReadAll

I have the ini file that names app.ini
this is located on the server but I but this also in a variable yet.
could you clear the other variables like Ip and so

thx

Top
#190664 - 2008-11-19 05:06 PM Re: Change string in ini file without a index [Re: Shajoca]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Glenn: yeah that an approach, but I was assuming that was only the beginning of what he might change and also trying to show how you can go trough each line. But golfing wise it can be even shorter using then your suggestion \:\)

Shajoca: I can't, those are the variables needed. Else try Glenn's suggestion.

Top
#190680 - 2008-11-20 08:35 AM Re: Change string in ini file without a index [Re: Arend_]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hi

but if I run the script the ini file will be not edited .
Can i copy the script of you with no change in the variables or can you specify me what i need to change in the script of you.
The only thing I could give you is the follwing
Ini file = app.ini
search string : ICO=
must be changed to = ico=mydomain

Many Thanks

Top
#190681 - 2008-11-20 08:49 AM Re: Change string in ini file without a index [Re: Shajoca]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Ok, here's the "Glenn/apronk" special:
 Code:
Dim $objFSO, $strIni, $objIni, $strTxt
$objFSO = CreateObject("Scripting.FileSystemObject")
$strIni = "C:\someinifile.txt"
$objIni = $objFSO.OpenTextFile($strIni, 8, 1)
$strTxt = $objIni.ReadAll
$strTxt = Join(Split($strTxt,"ICO=10.32.62.30"),"ICO=MyDomain")
$objIni.Write($strTxt)
$objIni.Close

Top
#190684 - 2008-11-20 09:11 AM Re: Change string in ini file without a index [Re: Arend_]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hi glenn is this correct ?

Dim $objFSO, $strIni, $objIni, $strTxt
$objFSO = CreateObject("Scripting.FileSystemObject")
$strIni = "C:\app.ini"
$objIni = $objFSO.OpenTextFile($strIni, 8, 1)
$strTxt = $objIni.ReadAll
$strTxt = Join(Split($strTxt,"ICO=10.32.62.30"),"ICO=MyDomain")
$objIni.Write($strTxt)
$objIni.Close

I also insert in attach the kix script and the ini file that must be changed --> ico= to ico=mydomain
thx


Attachments
Ibs.kix (174 downloads)
Description:

Acssetup.ini (162 downloads)
Description:




Edited by Shajoca (2008-11-20 09:34 AM)
Edit Reason: attachments

Top
#190690 - 2008-11-20 02:02 PM Re: Change string in ini file without a index [Re: Shajoca]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh well yeah,
this seems to be correct... apart from the fact that I am not a Glenn
_________________________



Top
#190691 - 2008-11-20 02:06 PM Re: Change string in ini file without a index [Re: Jochen]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hi thanks for help
but if I run this script , it will not change anything in the ini file .

Hopefully you could help me with this problem .
I need to configure this till tis evening , tommorow there will be a little migration of this application to a other server .
Otherwise I need to ga to each desktop for change ( 120 pcs) \:\(

thx a lot

Top
#190692 - 2008-11-20 02:09 PM Re: Change string in ini file without a index [Re: Shajoca]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hmmm... your strIni var is : C:\app.ini
but your attachment is called acssetup.ini.
Maybe this is the cause?
_________________________



Top
#190693 - 2008-11-20 02:14 PM Re: Change string in ini file without a index [Re: Jochen]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
Hello

no the full string is %programfiles%\IBSAnalyser60\Users\Local\Acssetup.INI
but I changed it for post on this forum .
It's not posdsible to change someting that is in the middle of a string in the ini file .

Thx

Top
#190694 - 2008-11-20 02:39 PM Re: Change string in ini file without a index [Re: Shajoca]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I had to fiddle a bit with it (seems that one can't read from a file that is open for writing)
...

This one worked for me:

 Code:
break on

Dim $objFSO, $strIni, $objIni, $strTxt
$objFSO = CreateObject("Scripting.FileSystemObject")
$strIni = "C:\149.ini"
$objIni = $objFSO.OpenTextFile($strIni, 1)
$strTxt = $objIni.ReadAll
$objIni.Close
$strTxt = Join(Split($strTxt,"ICO=10.32.62.30"),"ICO=MyDomain")
$objIni = $objFSO.OpenTextFile($strIni, 2)
$objIni.Write($strTxt)
$objIni.Close
_________________________



Top
#190695 - 2008-11-20 02:40 PM Re: Change string in ini file without a index [Re: Shajoca]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I think that there are some excellent examples posted above.
Below is an other way to get it done.

 Code:
Break on

$rc = Open(1, "c:\somefolder\inifile.ini")
$rc = Open(2, "c:\somefolder\new_inifile.ini")
$line = ReadLine(1)

While Not @ERROR
	If InStr($line, "ICO=10.32.62.30")
		$line = Split($line, "ICO=10.32.62.30")
		$line = Join($line, "ICO=Mydomain")
		$rc WriteLine(2, $line + @CRLF)
	Else
		$rc WriteLine(2, $line + @CRLF)
	EndIf
	$line = ReadLine(1)
Loop

$rc = Close(1)
$rc = Close(2)

Move "c:\somefolder\inifine.ini" "c:\somefolder\inifile.old"
Move "c:\somefolder\new_inifine.ini" "c:\somefolder\inifile.ini"
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190697 - 2008-11-20 04:02 PM Re: Change string in ini file without a index [Re: Mart]
Shajoca Offline
Fresh Scripter

Registered: 2008-09-04
Posts: 17
THX a lot to you all . it works now.
Top
#190698 - 2008-11-20 04:18 PM Re: Change string in ini file without a index [Re: Jochen]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
But you could be if you wanted to. Just think how much more on fire you could be with all of those rockets! \:\)
Top
#190699 - 2008-11-20 04:23 PM Re: Change string in ini file without a index [Re: BradV]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
lol.

I should really change the kixgolf avatar, eh?
_________________________



Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2175 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.072 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

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