Solved

Creating config XML from VBScript

Posted on 2009-05-19
6
807 Views
Last Modified: 2013-11-25
Hello,

I'm trying to create a vbscript that allows me to automate some deployments to our various environments. Each environment usually has the same config files. however they have different parameters for things like sql connection strings etc. I want to have a vbscript that is able to write like a web.config file with the paramters I choose. I couldn't find anything opensoruce for this. Anyone that is familiar with vbscript able to help? Attached is a beginning sample of a web.config file that I would want to generate using a vbscript. The endpoint address is what I would want to have as a variable as it varies in the different environments. :


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
	<configSections>
		<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
	</configSections>
	
	<system.diagnostics>
  <sources>
   <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
    <listeners>
     <add type="System.Diagnostics.DefaultTraceListener" name="Default">
      <filter type="" />
     </add>
    </listeners>
   </source>
   <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
    propagateActivity="true">
    <listeners>
     <add type="System.Diagnostics.DefaultTraceListener" name="Default">
      <filter type="" />
     </add>
    </listeners>
   </source>
  </sources>
 </system.diagnostics>
 <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
		<listeners>
			<add source="Enterprise Library Logging" formatter="Text Formatter"
     log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
     traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
     name="Formatted EventLog TraceListener" />
		</listeners>
		<formatters>
			<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
     type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
     name="Text Formatter" />
		</formatters>
		
		<logFilters>
			<add minimumPriority="0" maximumPriority="2147483647" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging" name="Priority Filter" />
		</logFilters>
 
		<categorySources>
			<add switchValue="All" name="AdServer">
				<listeners>
					<add name="Formatted EventLog TraceListener" />
				</listeners>
			</add>
		</categorySources>
 
		<specialSources>
			<allEvents switchValue="All" name="All Events" />
			<notProcessed switchValue="All" name="Unprocessed Category" />
			<errors switchValue="All" name="Logging Errors &amp; Warnings">
				<listeners>
					<add name="Formatted EventLog TraceListener" />
				</listeners>
			</errors>
		</specialSources>
	</loggingConfiguration>
 
	<system.serviceModel>
		<bindings>
   <netTcpBinding>
    <binding name="ORMBinding" receiveTimeout="00:00:00.2000000"
     maxConnections="1000">
     <readerQuotas maxStringContentLength="16384" />
    </binding>
   </netTcpBinding>
  </bindings>
		<diagnostics>
			<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
		</diagnostics>
		<client>
			<endpoint address="net.tcp://192.168.1.106:5151/Server"
    binding="netTcpBinding" bindingConfiguration="ORMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORMServer" />
		</client>
	</system.serviceModel>

Open in new window

0
Comment
Question by:hmsinfra
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Tompa99
ID: 24428888
Hi,

We are using T4 to solve the same problem that you have with multiple environments with just connection string and endpoint that is diffrent in our config files.

http://www.olegsych.com/2007/12/how-to-use-t4-to-generate-config-files/
and
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/

When you have it in place it works great for us.

Best Regrds Tompa

0
 
LVL 1

Author Comment

by:hmsinfra
ID: 24432074
Hey,

That took would work for another project, but for this I don't think it will work. Sometimes under heavy load we may need to take a PERF server and move it to PROD, and sometimes the PROD servers may have like different endpoint addresses. Is there a way to use something like VBScript to edit the XML file and replace lines like the attached code?

        <diagnostics>
            <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <client>
            <endpoint address="net.tcp://111.111.111.111:5050/Server"
    binding="netTcpBinding" bindingConfiguration="OMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORServer" />
        </client>
    </system.serviceModel>
 
 
replace the endpoint address= with
 
 <endpoint address="net.tcp://999.999.999.999:5050/Server"
    binding="netTcpBinding" bindingConfiguration="OMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORServer" />
 
 
See only the IP address changed?

Open in new window

0
 
LVL 1

Author Comment

by:hmsinfra
ID: 24435047
Also I found this page

http://www.devguru.com/technologies/xml_dom/15891.asp

Which makes it seem like its easy to simply add an attibute/replace. I however can't seem to get it working. Can anyone test and give me an example on how to replace the attributes?

Thanks!
0
 
LVL 1

Accepted Solution

by:
maytan80 earned 500 total points
ID: 24436590
You want this page...

http://www.devguru.com/technologies/xml_dom/15603.asp

Copy paste the following code to a vbs file, and save the vbs in the same folder as the webconfig.xml file. Comment out the MsgBox lines when you are sure the code works as planned.

setAddrValue = "net.tcp://192.168.1.106:5151/Server1"

set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("Webconfig.xml")

'Find the endpoint element
Set NodeList = objXMLDoc.getElementsByTagName("endpoint")
For Each Elem In NodeList
   MsgBox(Elem.tagName)
   Set elemAttr = Elem.Attributes
   For each attr in elemAttr
    MsgBox(attr.Name)
    MsgBox(attr.Value)

'Iterate till we find the address element
    If attr.Name = "address" Then
       attr.Value = setAddrValue
       MsgBox(attr.Value)
        objXMLDoc.Save("Webconfig.xml")      
    End If
  Next
Next
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Learn about cloud computing and its benefits for small business owners.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question