2012-07-30 2 views
1

무인 Windows7 설치에 사용할 응답 파일을 만들었습니다. 내가 몇 가지 설정을 즉시 수정할 수 (시간대, 컴퓨터 이름, 요법) 수 싶습니다,하지만 난 VBScript를/XML에 새로운 해요. 나는이 사이트에서 깔끔한 artical을 발견했다. xpath 사용 방법은 VBScript Find a node in XML node and replace the value이다. 내 문제 중 일부는 형식을 사용하는 예제를 찾지 못했기 때문에 노드를 대상으로합니다 (생각합니다). 전체 및 그냥,하지만 전체 응답 파일에서 동일한 구성 요소 이름 가진 여러 노드가 사용하여 시도했다. 제안 ... 제발? :)VBS를 사용하여 XML 검색 및 값 변경

<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> 

VB에서 혼란 스러울 정도로 혼자 힘으로 올라올 수있었습니다. 나는 그 포스트에 감사한다. 이렇게하면 사용자 상자도 프롬프트됩니다. 이와 같은 일이 효과적이지 않고 효율적으로 일하는 이유가 있습니까?

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") 

답변

0

이 스크립트

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 

출력 :

<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> 

는 XPath 식의 하여 SelectionNamespaces에게 재산 및 접두사를 사용하는 방법을 보여줍니다.

P. here을보고 (기본적으로 동일한 코드로) 속성을 찾고/변경하는 방법을 확인하십시오.

P.P.S : 똑같은

More.

+0

의견에 감사드립니다. 나는 꽤 잘하는 것처럼 보였던 (위에 언급 한) 것을 생각해 냈습니다. 이제 Inputbox()에 문제가있어 올바른 값이 있는지 확인하십시오. 나는 그것을 이해할 수 없다면 또 다른 질문을 시작할 것이다. –

관련 문제