1

I created an answer file to be used for an Unattended Windows7 install. I would like to be able to modify a few settings on the fly (Time Zone, computer name, ect), but I'm new with VBScript/XML. I found a neat artical on this site VBScript Find a node in XML node and replace the value on how to use xpath. Some of my trouble is targeting the node (I think) as I haven't found an example using format. I've tried using the full and just , but in the full answer file there are several nodes with the same component name. Suggestions...please? :)

<unattend xmlns="urn.schemas-microsoft.com:unattend">        
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="*REMOVED*" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ProductKey>*REMOVED*</ProductKey>
            <RegisteredOwner>*REMOVED*</RegisteredOwner>
            <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
            <ComputerName>*</ComputerName>
            <DoNotCleanTaskBar>true</DoNotCleanTaskBar>
            <BluetoothTaskbarIconEnabled>false</BluetoothTaskbarIconEnabled>
            <CopyProfile>true</CopyProfile>
            <ShowWindowsLive>false</ShowWindowsLive>
            <TimeZone>VarTime</TimeZone>
        </component>
    </settings>
</unattend>

Messing around with VBs, I was able to come up with someone on my own. I do appreciate the post. This prompts for a user box as well. Is there any reason why something like this wouldn't work and do the job efficiently?

Set xml = CreateObject("Msxml2.DOMDocument.3.0")

xml.Async = "False"
xml.load "path.xml"

strTime = InputBox("Please Select your Time Zone.")
strTimeZone = "Nothing"         

if strTime= "1" then strTimeZone= "Eastern Standard Time"
if strTime= "2" then strTimeZone= "Central Standard Time"
if strTime= "3" then strTimeZone= "Mountian Standard Time"
if strTime= "4" then strTimeZone= "Pacific Stardard Time"

Set TimeZone = xml.selectSingleNode("//unattend/settings/component/TimeZone")


TimeZone.Text = strTimeZone

'Save the xml document with the new settings.
strResult = xml.save("path.xml")
Community
  • 1
  • 1
Lost_Confused
  • 13
  • 1
  • 4

1 Answers1

0

This script

  Dim oFS    : Set oFS  = CreateObject("Scripting.FileSystemObject")
  Dim sFSpec : sFSpec   = oFS.GetAbsolutePathName("..\testdata\xml\ns-xpath-01.xml")
  Dim sNS    : sNS      = "xmlns:a='urn.schemas-microsoft.com:unattend'"
  Dim oXML   : Set oXML = CreateObject("Msxml2.DOMDocument")
  oXML.setProperty "SelectionLanguage", "XPath"
  oXML.setProperty "SelectionNamespaces", sNS
  oXML.async = False
  oXML.load sFSpec
  If 0 = oXML.parseError Then
     WScript.Echo oXML.xml
     WScript.Echo "-----------------"
     Dim sXPath : sXPath    = "/a:unattend/a:settings/a:component/a:TimeZone"
     Dim ndFnd  : Set ndFnd = oXML.selectSingleNode(sXPath)
     If ndFnd Is Nothing Then
        WScript.Echo sXPath, "not found"
     Else
        WScript.Echo ndFnd.text
        WScript.Echo "-----------------"
        ndFnd.text = "Abracadabra"
        WScript.Echo oXML.xml
     End If
  Else
     WScript.Echo oXML.parseError.reason
  End If

output:

<unattend xmlns="urn.schemas-microsoft.com:unattend">
        <settings pass="specialize">
                <component>
                        <TimeZone>VarTime</TimeZone>
                </component>
        </settings>
</unattend>

-----------------
VarTime
-----------------
<unattend xmlns="urn.schemas-microsoft.com:unattend">
        <settings pass="specialize">
                <component>
                        <TimeZone>Abracadabra</TimeZone>
                </component>
        </settings>
</unattend>

shows how to use the SelectionNamespaces property and prefixes in the XPath expression.

P.S. Look here to see how to look for/change attributes (with essentially the same code).

P.P.S:

More of the same.

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Thanks for the feedback. I was able to come up with something (noted above) that seemed to work out pretty well. Now I'm having troubles with the Inputbox() and making sure the correct values are there. I'll start another question if I can't figure it out. – Lost_Confused Jul 31 '12 at 19:26