0

i need to add the value of ExtraDataItem name="HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress" value="192.168.2.1" to my xml.. In the picture you can see how it looks after it has been added by the program. In the default xml, only 2 lines exist in ExtraData.

Can you please tell me how to do it using Msxml2? i tried with this code, but no results :(

Set xmlDoc = CreateObject("Msxml2.DOMDocument")

xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.load(file1)

Set objNodeList = xmlDoc.getElementsByTagName("DHCPServers")

For each comNodeItem in objNodeList
    'JobName = comNodeItem.getAttribute("name")
    for each fileNodeItem in comNodeItem.ChildNodes
        fileName = fileNodeItem.getAttribute("IPAddress")
        fileNodeItem.setAttribute "IPAddress", "192.168.2.10"
        fileName = fileNodeItem.getAttribute("lowerIP")
        fileNodeItem.setAttribute "lowerIP", "192.168.2.2"
        fileName = fileNodeItem.getAttribute("upperIP")
        fileNodeItem.setAttribute "upperIP", "192.168.2.9"
    next
Next

Set objNodeList = xmlDoc.getElementsByTagName("ExtraData")

For each comNodeItem in objNodeList
    'JobName = comNodeItem.getAttribute("name")
    for each fileNodeItem in comNodeItem.ChildNodes
        fileName = fileNodeItem.getAttribute("ExtraDataItem name")
        comNodeItem.createAttribute "HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress"
        fileName = fileNodeItem.getAttribute("value")
        fileNodeItem.setAttribute "value", "192.168.2.1"
    next
Next

xmlDoc.save(file1)

enter image description here

Pankaj Jaju
  • 5,371
  • 2
  • 25
  • 41

1 Answers1

1

File says DO NOT EDIT THIS FILE.

If you need to programmatically modify the VirtualBox configuration, use the appropriate tools:

VBoxManage setextradata global "HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress" "192.168.2.1"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • that is not a problem, ignore the part "DO EDIT..." VBoxManage didn;t work, need to add it with vbs ;) – user3433877 Mar 19 '14 at 07:32
  • @user3433877 If `VBoxManage` didn't work (how *exactly* did it "not work"?) you should fix that issue, not work around it. – Ansgar Wiechers Mar 19 '14 at 10:15
  • the value that i was trying to modify was the virtual network adapter's IP, that's why it was not changed from the xml. I used a cmd and netsh to change that ip and everything is fine now. Also, i used vboxmanage to modify the xml settings, which was way simpler than editing the xml. Problem solved. – user3433877 Mar 20 '14 at 11:43