EDIT CONFIG FILE with batch file

April 27, 2009 at 03:02:55
Specs: Windows XP
I have a config file like this:-


<?xml version="1.0"?>


<configuration>
<appSettings>

<add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/>
<add key="MessagesFile" value="C:\XTMS\XTMSService\XTMSConfig\XTMSMessages.xml"/>
<add key="EmailConfig" value="C:\XTMS\XTMSService\XTMSConfig\EmailConfig.xml"/>
<add key="SmtpClient" value="mailhost.css.mc.xerox.com"/>

</appSettings>
<connectionStrings>

<add name="OracleConnectionold" connectionString="Data Source=ooosd;User ID=xkk1; Password=sda; Unicode=True" providerName="System.Data.OracleClient"/>
<add name="OracleConnection" connectionString="Data Source=ooop;User ID=dds; Password=fafa2009; Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
</configuration>


I am creating a batch file in which user will give the input.that input will decide which database will the application be connecting to.I want to Open this config file and edit the connection string.How can this be done??I am using windows XP


See More: EDIT CONFIG FILE with batch file

Report •


#1
April 27, 2009 at 04:03:35
if you have Perl on Windows and can use it
my $config="file";
print "Enter Data Source: ";
my $datasrc = <STDIN>;chomp($datasrc);
print "Enter UserID: ";
my $userid = <STDIN>;chomp($userid);
print "Enter Unicode(True or False: ";
my $unicode = <STDIN>;chomp($unicode);
print "Enter password: ";
my $pass = <STDIN>;chomp($pass);
$string = "Data Source=".$datasrc.";User ID=".$userid."; Password=".$pass.";Unicode=".$unicode;

while(<>){
 chomp;
 if (/<add name=\"OracleConnection\"/ ){
    s/connectionString="(.*?)\"/connectionString="$string"/;
 }
 print $_."\n";
} 

output:

# perl test.pl file
Enter Data Source: new_data_source
Enter UserID: new_user_id
Enter Unicode(True or False: False
Enter password: new_pass
<?xml version="1.0"?>


<configuration>
<appSettings>

<add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/>
<add key="MessagesFile" value="C:\XTMS\XTMSService\XTMSConfig\XTMSMessages.xml"/>
<add key="EmailConfig" value="C:\XTMS\XTMSService\XTMSConfig\EmailConfig.xml"/>
<add key="SmtpClient" value="mailhost.css.mc.xerox.com"/>

</appSettings>
<connectionStrings>

<add name="OracleConnectionold" connectionString="Data Source=ooosd;User ID=xkk1; Password=sda; Unicode=True" providerName="System.Data.OracleClient"/>
<add name="OracleConnection" connectionString="Data Source=new_data_source;User ID=new_user_id; Password=new_pass;Unicode=False" providerName="System.Data.OracleClient"/>
</connectionStrings>
</configuration>

Unix Win32 tools | Gawk for Windows


Report •

#2
April 27, 2009 at 04:28:16
No I am trying to work on .Bat file which will be executed in command prompt.
I Also want some code that can replace
C:\ to D:\ if user enters D.
<add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/>
Thnx alot by the way for giving your time to it.

Report •

#3
April 27, 2009 at 08:00:33
Please Reply ASAP

Report •

Related Solutions


Ask Question