?
Solved

Creating config XML from VBScript

Posted on 2009-05-19
6
Medium Priority
?
855 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
4 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
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…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

621 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