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.
.Bat to edit CONFIG file
Moderator: DosItHelp
Re: .Bat to edit CONFIG file
A Batch-JScript hybrid may help.
Regards
aGerman
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
-
- Posts: 2
- Joined: 11 Aug 2016 21:10
Re: .Bat to edit CONFIG file
I really appreciate your help in resolving my problem.Thx you so much ...