'Vb scrpit modify the configuration file (XML ):
Dim wshshellset wshshell = Createobject ("wscript. shell ") set FSO = Createobject (" scripting. fileSystemObject ") 'create log file for the script set logstream = FSO. createtextfile ("updateconfig. log ", true) logstream. writeline "Start update config" 'assumes that the file to be modified is a database configuration file, to update datasource and datasourcemirror, the two elements datasource = "localhost" Export cemirror = "localhost" 'are assumed to be from another test. read the values of datasource and datasourcemirror in XML and update them to configfile. configtestpath = "test. XML "set xmldoc = Createobject (" msxml2.domdocument ") if (FSO. fileexists (testpath) Then MSG = nboxconfigfilepath & "exists" logstream. writeline MSG 'Load the test config file xmldoc. load (testpath) 'assumes test. the XML structure is relatively complex. Use XPath to search for the corresponding node: Set nodes cenode = xmldoc. selectsinglenode ("// test [@ name = 'datasource ']"). parentnode set parameter cemirrornode = xmldoc. selectsinglenode ("// test [@ name = 'your cemirror ']"). parentnode' gets the node attribute value datasource = pipeline cenode. getattribute ("name") Export cemirror = export cemirrornode. getattribute ("name") else MSG = "warning" & testpath & "doesn't exists" 'If the testpath does not exist, write the warning information to the log file logstream. writeline MSG end if set wshenv = wshshell. environment ("process") ', replace config Dir and configfile with the corresponding content filepath = "configdir/configfile. config "If (FSO. fileexists (filepath) Then MSG = filepath & "exists" 'If the filepath does not exist, write the warning information to the log file logstream. writeline MSG 'loading config file xmldoc. load (filepath) logstream. writeline "loading config file" & filepath 'get the datasource and mirror node set rt1_cenode = xmldoc. selectsinglenode ("// Add [@ key = 'datasource ']") set rt1_cemirrornode = xmldoc. selectsinglenode ("// Add [@ key = 'clock cemirror ']") 'set the value attribute for the datasource and mirror node rt1_cenode. setattribute "value", datasource rt1_cemirrornode. setattribute "value", export cemirror 'Save the config file xmldoc. save (filepath) logstream. writeline "Save the config file" logstream. writeline "finish the configuration" else MSG = "error:" & filepath & "doesn' t exists" end if logstream. close 'release wshshell set wshshell = nothing
Example of configfile. config:
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Deleetask>
<Add key = "datasource" value = "localhost"/>
<Add key = "datasourcemirror" value = "localhost"/>
<Add key = "initialcatalog" value = "testdb"/>
</Appsettings>
</Configuration>