View Full Version : Editing web.config with InstallScript CA

05-10-2004, 01:10 PM
Well, after working on this for a number of days, searching here and on other sites for help, I thought there may be others out there who could use this.

I have a web application with a customized web.config file. Meaning we have added appSettings 'add' nodes, with key/value pairs which are used within the app to control certain behaviour.

The config file, being XML, can be read and manipulated with the XML DOM. Not an easy task for me, since documentation is a little fragmented between IS, MS, etc. But doable.

I created a Custom Action which executes after InstallFinalize, where it finds and opens the config file, finds the nodes I need to change, and then subs public variable values to the nodes.

This allows our Network Admin to install the application without having to edit the config file directly. We can also remove a number of comments out of the config, since instructions are now on the user dialog of the install.

Anyway, HTH anyone out there with a similar need!


07-14-2004, 09:35 AM
I notice that this function seems to only update an existing key in the webconfig file...any idea on how to add a new key and value if it doesn't exist in the webconfig file?


07-15-2004, 10:55 AM
Thanks! It is very useful.

10-14-2004, 02:42 PM
set oDoc = CreateObject("Msxml2.DOMDocument.4.0");
if (IsObject(oDoc) = FALSE) then
return -1;

for some reason IsObject(oDoc) = FALSE and i can not figure out why...am I missing something?


06-02-2008, 01:19 AM
I am having the same problem. Anyone know why it can't create an xml doc with the statement :

// Set XML Doc Type
set oXMLdoc = CreateObject("Msxml2.DOMDocument.4.0");
if (IsObject(oXMLdoc) = FALSE) then
MessageBox("Error creating XML doc", 0);

06-02-2008, 06:16 PM
If you look in the registry (HKCR), is that version of MSXML registered? Perhaps use the version-independent ProgID "Msxml2.DOMDocument"?

06-02-2008, 06:21 PM
Thankyou for the pointer!!!

My registry was showing Msxml2.DOMDocument.6.0.
I changed my code to reference 6.0 instead fo 4.0, and have also included the MSXML 4.0 redistributable to ensure there are no problems at client sites.

06-02-2008, 06:34 PM
Actually, you might try version-indept. CreateObject("Msxml2.DOMDocument"), which should resolve to the current registered version on a target system...

06-02-2008, 06:37 PM
OK, thankyou for the advice, I will change the scripting.
Would I still need to include the redistributable in this scenario?

06-02-2008, 06:44 PM
Probably, just in case the target system doesn't have any version available...

04-16-2009, 01:48 AM
Thanks for this..

06-09-2009, 05:51 AM

I have another XML file with this structure (The XML files belong to an already installed application, only some changes are needed in them):


I have to modify the first occurence of <IpAddress>*</IpAddress> to <IpAddress>${BindAddress}</IpAddress> and <Port>1935</Port> to <Port>${RTMPPort}</Port> (this values actually)

I modified the script like this:

if oDoc.load(configFile) then
// if success, traverse file and substitute value
// get list of matching nodes
set oNodeList = oDoc.getElementsByTagName("HostPort");
if (oNodeList.length > 0) then
for i = 0 to (oNodeList.length - 1);
set oNode = oNodeList.nextNode;
switch (oNode.attributes.getNamedItem("key").value)
case "IpAddress":
bindIpAddr = "${BindAddress}";
oNode.attributes.getNamedItem("value").value = bindIpAddr;
case "Port":
bindPort = "${RTMPPort}";
oNode.attributes.getNamedItem("value").value = bindPort;

When I call the function


The error I get is:
Error number: 0x80040706
Object reference not set

Setup will now terminate.

I notice that the script gets to switch (oNode.attributes.getNamedItem("key").value) and there fails and don't know the reason.

Could you please advise.

Also I need to add new elements in 2 XML files and I have no ideea how to do it.