Editing an .ini file

October 7, 2009 at 00:55:34
Specs: Windows Vista
Hello, I am new to batch files but my issue is simple , I believe

I would like to use a batch file to edit content of an .ini file

the .ini file is located in my windows folder , I am assuming that changes will be coming from the local folder of the batch file. I am unsure with the file structure as well

here is my dillemma:


needs to be


how do i do this?


See More: Editing an .ini file

Report •

October 8, 2009 at 15:25:21
my issue is simple , I believe
Changing the contents of a file is one of the hardest tasks in Batch Scripting.

VBScript is much easer to use, though:

ret = Main
WScript.Echo "Done"
WScript.Quit ret

Function Main
  Const fileName = "C:\whatever.ini"
  Set fso = CreateObject("Scripting.FileSystemObject")

  iniText = fso.OpenTextFile(fileName).readAll
  RepSetting iniText, "Connect", """rrrr;DSN=fffff"""
  RepSetting iniText, "DataSourceType", "0"
  RepSetting iniText, "NTAuthenticate", "0"
  fso.OpenTextFile(fileName, 2).Write iniText
  Main = 0
End Function

Sub RepSetting(ByRef iniText, settingName, newValue)
  With New regExp
    .IgnoreCase = True
    .Global = True
    .Pattern = settingName & "=.*\n"
    iniText = .Replace(iniText, settingName & "=" & newValue & vbNewLine)
  End With
End Sub

Report •

October 11, 2009 at 20:48:06
edlin can be used with a pipeable batchfile:
:--------- f.bat
goto xx
edlin [filename] < f.bat

edlin is a poorer version of unix's sed but it does
have some abilities so i try to keep a copy around.

Report •

Related Solutions

Ask Question