adding text into specific location into .ini

Kingston 256mb module for dell poweredge...
July 29, 2009 at 00:50:13
Specs: Windows XP
i need to add a specific line of text into a specific location after finiding the word [ORAGTWY] the below is the .ini file which i need to add the text into it:


; Settings for 25-User-SqlBase Server
[dbnt25sv]
country=germany
cache=2000
sortcache=2000
readonly=0
oracleouterjoin=0
logfileprealloc=0
partitions=0
optimizerlevel=2
locktimeout=275

[dbnt25sv.dll]
comdll=sqlws32
comdll=sqlapipe

[win32client]
country=germany
clientname=Win32User
SetZeroLengthStringsToNull=ON

[win32client.dll]
comdll=sqlws32
comdll=sqlora32
comdll=sqlodb32

[win32client.ws32]
serverpath=SRVxxx,<localhost>/WCxxx

[ORAGTWY]
REMOTEDBNAME=pos401a1,@pos401a1
REMOTEDBNAME=posprd2,@posprd2
REMOTEDBNAME=bscsprd2,@bscsprd2
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=SIEBPRD2,@SIEBPRD2


servername=server1
REMOTEDBNAME=WCDB,@WCDB

[ODBCRTR]

[SQLTALK]
country=germany

[SQLAPIW]
country=germany


See More: adding text into specific location into .ini

Report •


#1
July 29, 2009 at 02:15:50
plz i need any response

Report •

#2
July 29, 2009 at 04:34:35

@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (my.ini) do (
echo %%a >> newfile
if %%a equ [ORAGTWY] (
echo my text >> newfile
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
July 29, 2009 at 04:46:35
Dear Mechanix2Go,
Thanks for the reply but what you replied with was a script to create a new file "newfile" and copy all the contents of the old file into it and insert the text i want if i find the specific word, which is perfect except that i only want to INSERT in the old file (i.e; edit the old file rather than create the new file)..is that possible?
Thanks alot anyways.

Report •

Related Solutions

#4
July 29, 2009 at 05:24:41
Dear Mechanix

plz i need your help as fast as you can i have a change tonight on 300 machine :D

Thanks for your support


Report •

#5
July 29, 2009 at 05:40:37
It's usually not a good idea to modify a file which is open for reading.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
July 29, 2009 at 06:05:27
no it's not open cause it will be done after working hours

Report •

#7
July 29, 2009 at 06:50:24
is there any solution plz i need your help

Report •

#8
July 29, 2009 at 07:18:45
I don't know of a way to read & write at the same time. What's wrong with creating a new file?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#9
July 29, 2009 at 18:30:03
@labib, it is YOUR job to try and do this yourself in the first place. therefore, as much as M2 wants to help you, do not exploit his kindness by "rushing" him to do YOUR job.

that said, with batch or vbscript(AFAIK), there is no mechanism to edit a file in place. If you want, download sed for windows which provides you this capability.

GNU win32 packages | Gawk


Report •

#10
August 19, 2009 at 13:07:35
Ghost I hate to get into the middle of pissing matches, but technically you are correct that you can't read and write the file at the same time, but that's not saying that you can't use VBScript to read the file into memory, then write from memory to the existing file with the added lines. Even though I am pretty new to writing scripts you can do something like the following to complete the task without having to create a new file.

strNewLine = "New Line to Write"
strFileName = "c:\test.ini"
strCheckForString = UCase("[ORAGTWY]")

Set objFS = CreateObject("Scripting.FileSystemObject")
StrContents = Split(objFS.OpenTextFile(strFileName).ReadAll, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, 2)
For Each strLine In StrContents
If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) Then
objTS.WriteLine strLine: objTS.WriteLine strNewLine
else
objTS.WriteLine strLine
End If
Next
Wscript.quit


Report •

#11
August 21, 2009 at 04:56:06
Simply use C and Win32 INI apis
See on Win32 ng
http://tinyurl.com/cmhb5g
for C code.

Report •


Ask Question