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

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

3 Comments

that is not a problem, ignore the part "DO EDIT..." VBoxManage didn;t work, need to add it with vbs ;)
@user3433877 If VBoxManage didn't work (how exactly did it "not work"?) you should fix that issue, not work around it.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.