Announcement

Collapse
No announcement yet.

Insert VBscript string into XML file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Insert VBscript string into XML file

    I have an xml file that is used as a config for a program. What I am trying to do, is insert the PC's computer name into the xml file...it looks somewhat similar to this:

    Code:
    <?xml version="1.0"?>
    <config type="program" version="version" guid="{E4E51EFC-E448-4600-BBEF-5798FBD9F1C1}">
    	<setting>
    		<key-path>Data Transfer\Statistics</key-path>
    		<value-name>Computer_Name</value-name>
    		<value-type>string</value-type>
    		<value>strComputerName</value>
    	</setting>
    </config>
    How would I incorporate this piece of code to go into the xml file:

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    strComputerName = WshNetwork.ComputerName
    I have tried this...but with no success:

    Code:
    <config type="program" version="version" guid="{E4E51EFC-E448-4600-BBEF-5798FBD9F1C1}">
    	<setting>
                     Set WshNetwork = WScript.CreateObject("WScript.Network")
                     strComputerName = WshNetwork.ComputerName
    		<key-path>Data Transfer\Statistics</key-path>
    		<value-name>Computer_Name</value-name>
    		<value-type>string</value-type>
    		<value>strComputerName</value>
                     WScript.Quit
    	</setting>
    </config>

  • #2
    Re: Insert VBscript string into XML file

    Have you considered using a VBScript to create the entire XML file vs. trying to embed some active code inside a passive XML file?

    As an old dog and without any other info on the environment / circumstances surrounding your problem, that's what I'd do.
    Cheers,

    Rick

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

    Comment


    • #3
      Re: Insert VBscript string into XML file

      The problem is that the program has to load the config as an xml file...not vbs. So yes I have looked that up...but it will not work in my case.

      Comment


      • #4
        Re: Insert VBscript string into XML file

        So you are not able to make a wrapper, say a .CMD file, that calls a .VBS script to build a specific .XML file then launches the program which, in turn, reads that .XML file?

        It's late for me so I may be missing a finer point in your problem.
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment


        • #5
          Re: Insert VBscript string into XML file

          Yeah I think that still won't work, because you have to load an .xml file and .xml file only from the program...

          EDIT* I've also tried inserting <script type = "text/vbscript"></script> tags wrapping the code into the xml file at several different locations, but with no success.
          Last edited by ekrengel; 21st February 2008, 02:36.

          Comment

          Working...
          X