Sign in to follow this  
Followers 0
NDog

[Solved] xmldom change productkey in unattend.xml

3 posts in this topic

#1 ·  Posted (edited)

I have read a few posts here and spent a few hours hacking away but no success. I am trying to change the product key in an xml.

So far I am trying to get the correct XPath syntax to a certain xml section, using a debug I keep getting -1. Maybe someone could show me the correct XPath string to use, then I should be able to change the xml section

unattend.xml

<?xml version='1.0' encoding='utf-8'?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="oobeSystem">
     <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <TimeZone>New Zealand Standard Time</TimeZone>
         <AutoLogon>
             <Enabled>true</Enabled>
             <LogonCount>1</LogonCount>
             <Username>Administrator</Username>
         </AutoLogon>
     </component>
     <component name="Microsoft-Windows-International-Core" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <InputLocale>en-NZ</InputLocale>
         <SystemLocale>en-US</SystemLocale>
         <UILanguage>en-US</UILanguage>
         <UILanguageFallback>en-US</UILanguageFallback>
         <UserLocale>en-NZ</UserLocale>
     </component>
</settings>
<settings pass="specialize">
     <component name="Microsoft-Windows-International-Core" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <InputLocale>en-US</InputLocale>
         <SystemLocale>en-US</SystemLocale>
         <UILanguage>en-US</UILanguage>
         <UILanguageFallback>en-US</UILanguageFallback>
         <UserLocale>en-NZ</UserLocale>
     </component>
     <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <ProductKey>xxxxxxxxxxxxxxxxxxxxxx</ProductKey>
         <TimeZone>New Zealand Standard Time</TimeZone>
         <ComputerName>*</ComputerName>
         <ShowWindowsLive>false</ShowWindowsLive>
     </component>
     <component name="Microsoft-Windows-Deployment" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <RunSynchronous>
             <RunSynchronousCommand wcm:action="add">
                 <Order>1</Order>
                 <Path>net user administrator /active:yes</Path>
                 <Description>Enable Administrator account</Description>
             </RunSynchronousCommand>
         </RunSynchronous>
     </component>
     <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <SkipAutoActivation>true</SkipAutoActivation>
     </component>
</settings>
<settings pass="auditSystem">
     <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <AutoLogon>
             <Username>Administrator</Username>
             <Enabled>true</Enabled>
             <LogonCount>1</LogonCount>
         </AutoLogon>
     </component>
</settings>
<settings pass="auditUser">
     <component name="Microsoft-Windows-Deployment" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <RunSynchronous>
             <RunSynchronousCommand wcm:action="add">
                 <Path>C:\Windows\Setup\scripts\syncrun.cmd</Path>
                 <Order>1</Order>
                 <Description>First Run</Description>
             </RunSynchronousCommand>
         </RunSynchronous>
     </component>
</settings>
</unattend>

code I have tried. Hope someone can point out my mistake

#include <array.au3>
#include <_XMLDomWrapper.au3>

$sXmlFile = "c:\windows\Panther\unattend.xml"
$sXPath = '/unattend/settings[@pass="specialize"]/component[@name="Microsoft-Windows-Shell-Setup"]/ProductKey'

$iRet = _XMLFileOpen($sXmlFile)
ConsoleWrite("Debug: $iRET = " & $iRET & @LF)

$aRET = _XMLGetValue($sXPath)
_ArrayDisplay($aRET, "Before")

_XMLUpdateField($sXPath, "xxxxx-yyyyy-zzzz-xxxxx-yyyyy")

$aRET = _XMLGetValue($sXPath)
_ArrayDisplay($aRET, "After")

Have also tried wraithdu xmldomwrapper code but cant figure out what to pass the additional strings required in the functions..

Edited by NDog

Share this post


Link to post
Share on other sites



I have seen some people have the same issue here http://www.microsoftfaqs.com/msg/14592596.aspx

The problem is the XPath <unattend xmlns="urn:schemas-microsoft-com:unattend">

With MSXML you do that as follows (JScript pseudo code):
   var doc = new ActiveXObject('Msxml2.DOMDocument.6.0');
   doc.async = false;
   if (doc.load('file.xml'))
   {
      doc.setProperty('SelectionNamespaces', 
'xmlns:ua="urn:schemas-microsoft-com:unattend"');
      // now use prefix 'ua' in XPath expressions passed to
      // selectNodes or selectSingleNode e.g.
      var settings = doc.selectSingleNode('ua:unattend/ua:settings');
   }
   else
   {
     // handle parseError here
   }

Im not sure how to convert this to autoit, I hope someone could help with that

:D

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok using the advice from PsaltyDS at

I was able to solve this, thanks PsaltyDS!

$sXML = "c:windowsPantherunattend.xml"
$sXmlNS = '"urn:schemas-microsoft-com:unattend"'
$sXmlQuery = '/MyNS:unattend/MyNS:settings[@pass="specialize"]/MyNS:component[@name="Microsoft-Windows-Shell-Setup"]/MyNS:ProductKey'
$iRET = _XMLFileOpen($sXML)
ConsoleWrite("$iRET = " & $iRET & @LF)

$objDoc.setProperty("SelectionNamespaces", 'xmlns:MyNS=' & $sXmlNS)

$aRET = _XMLGetValue($sXmlQuery)
If IsArray($aRET) Then
_ArrayDisplay($aRET, "Before")
_XMLUpdateField($sXmlQuery, xxxxx-yyyyy-xxxxx-yyyyy-xxxxx)
$aRET = _XMLGetValue($sXmlQuery)
_ArrayDisplay($aRET, "After")
Else
ConsoleWrite("Error, $aRET = " & $aRET & @LF)
EndIf
EndIf
Edited by NDog

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0