Computing.Net > Forums > Programming > EDIT CONFIG FILE with batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

EDIT CONFIG FILE with batch file

Reply to Message Icon

Name: techhelp
Date: April 27, 2009 at 03:02:55 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 27, 2009 at 04:03:35 Pacific
Reply:

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


0

Response Number 2
Name: techhelp
Date: April 27, 2009 at 04:28:16 Pacific
Reply:

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.


0

Response Number 3
Name: techhelp
Date: April 27, 2009 at 08:00:33 Pacific
Reply:

Please Reply ASAP


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


How to read a file using ... create a folder



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: EDIT CONFIG FILE with batch file

editing text file with batch file www.computing.net/answers/programming/editing-text-file-with-batch-file/15231.html

Editing a txt file with batch files www.computing.net/answers/programming/editing-a-txt-file-with-batch-files/19270.html

editing text file with a batch file www.computing.net/answers/programming/editing-text-file-with-a-batch-file/16828.html