.Bat to edit CONFIG file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kakikupart
Posts: 2
Joined: 11 Aug 2016 21:10

.Bat to edit CONFIG file

#1 Post by kakikupart » 11 Aug 2016 21:44

Good Morning :)

I am trying to work on .Bat file which will be executed in command prompt to edit the CONFIG file.
I also want some code that can replace in CONFIG file
From C:\XXX to YYY:\ if user enters YYY.

Here is my CONFIG file

<configuration>
<appSettings>
<add key="SystemURL" value="http://localhost" />
<add key="SystemRoot" value="C:\CRM" />
<add key="BBID" value="XXX" />
</appSettings>
</configuration>

Your time and help is greatly appreciated.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: .Bat to edit CONFIG file

#2 Post by aGerman » 12 Aug 2016 11:21

A Batch-JScript hybrid may help.

Code: Select all

@if (@a)==(@b) @end /* Batch portion:

@echo off &setlocal

set "xmlfile=test.config"

set /p "sysroot=Enter the system root: "
cscript //nologo //e:jscript "%~fs0" "%xmlfile%" "%sysroot%"

exit /b


JScript portion: */

var oXmlDoc = new ActiveXObject('Microsoft.XMLDOM');
oXmlDoc.load(WScript.Arguments(0));
var i, nodes = oXmlDoc.getElementsByTagName('add');
for (i = 0; i < nodes.length; i++) {
  if (nodes[i].getAttribute('key') == 'SystemRoot') {
    nodes[i].setAttribute('value') = WScript.Arguments(1) + ':\\';
    break;
  }
}

oXmlDoc.save(WScript.Arguments(0));

Regards
aGerman

kakikupart
Posts: 2
Joined: 11 Aug 2016 21:10

Re: .Bat to edit CONFIG file

#3 Post by kakikupart » 20 Aug 2016 03:09

I really appreciate your help in resolving my problem.Thx you so much ...

Post Reply