Jump to content

_XMLDomWrapper & Untattend.xml for Windows Seven


NDTC
 Share

Recommended Posts

Hi all,

I'll go crazy with this stuff:

I try to modify the answer file sysprep Unattend.xml for Windows Seven.

Here's what I want to:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
   <servicing></servicing>
   <settings pass="specialize">
      ... ...
[color="#FF0000"]      <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">
               <Description>Drivers Setup</Description>
               <Order>1</Order>
               <Path>cmd /c C:\Drivers\SetupDrivers.cmd</Path>
            </RunSynchronousCommand>
            <RunSynchronousCommand wcm:action="add">
               <Description>Drivers Setup 2</Description>
               <Order>2</Order>
               <Path>cmd /c C:\Drivers\SetupDrivers2.exe /S</Path>
            </RunSynchronousCommand>
         </RunSynchronous>
      </component>[/color]
   </settings>
   ... ...
</unattend>

To do this, I realized this code snippet:

#include <_XMLDomWrapper.au3>

Global $SYSPREPFile = @ScriptDir & "\Unattend.xml"

FileCopy("unattend.xml", "Unattend_" & FileGetTime("unattend.xml", 0, 1) & ".xml")

_XMLFileOpen($SYSPREPFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"')
Switch @error
    Case 1
        ConsoleWrite("Parse Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
EndSwitch
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr ('//un:unattend', 'settings', "pass", "specialize", "urn:schemas-microsoft-com:unattend")
EndIf
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr ('//un:unattend/un:settings[@pass="specialize"]', "component", "name", "Microsoft-Windows-Deployment")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "processorArchitecture", "x86")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "language", "neutral")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "publicKeyToken", "31bf3856ad364e35")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "versionScope", "nonSxS")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
 EndIf
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous" not exist' & @CRLF)
    $Temp = _XMLCreateChildNode ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "RunSynchronous", "", "urn:schemas-microsoft-com:unattend")
EndIf
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous', "RunSynchronousCommand", "wcm:action", 'add')
EndIf
$Temp = _XMLCreateChildNode ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]', "Description", "Drivers Setup", "urn:schemas-microsoft-com:unattend")
$Temp = _XMLCreateChildNode ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]', "Order", "1", "urn:schemas-microsoft-com:unattend")
$Temp = _XMLCreateChildNode ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]', "Path", "cmd /c C:\Drivers\SetupDrivers.cmd", "urn:schemas-microsoft-com:unattend")
Exit

But this is what it gives:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
   <servicing></servicing>
   <settings pass="specialize">
[color="#FF0000"]      <component xmlns="" name="Microsoft-Windows-Deployment"/>[/color]   </settings>
</unattend>

I tried several combinations, but nothing was done ...

If someone has a solution, I'm interested because I do not leave...

Please Help!!!

Thank's by advance...

Link to comment
Share on other sites

@NDTC: I'm still looking at it, because I'm having a teachable moment here and learning some XML namespace stuff.

First thing is this needs fixed because you left out an unused parameter before the namespace, causing the namespace URI to be the value instead of in the xmlns attribute:

$Temp = _XMLCreateChildWAttr('//un:unattend', 'settings', "pass", "specialize", "", "urn:schemas-microsoft-com:unattend")

@wraithdu is right, this should be in General Help and Support. I'll ask a Mod to move it.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

@NDTC: Second problem is that you specified "un:component" as the location to create the attributes, but didn't assign that namespace when creating it. Change the line to:

$Temp = _XMLCreateChildWAttr('//un:unattend/un:settings[@pass="specialize"]', "component", "name", "Microsoft-Windows-Deployment", "", "urn:schemas-microsoft-com:unattend")

:D

Third, and same problem as the second, is using "un:RunSynchronousCommand" when you didn't specify that namespace on creation. Should be:

$Temp = _XMLCreateChildWAttr('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous', "RunSynchronousCommand", "wcm:action", 'add', "", "urn:schemas-microsoft-com:unattend")

:huggles:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Just learning the namespace stuff myself, and I got this far:

Starting from this XML file (Test1.xml):

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
</unattend>

I run this version of your script (successfully creating all the nodes verifies the syntax):

#include <_XMLDOMWrapper.au3>

$debugging = True

Global $SYSPREPFile = @ScriptDir & "\Test1.xml"

_XMLFileOpen($SYSPREPFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"')
Switch @error
    Case 1
        ConsoleWrite("Error:  Parse Error" & @CRLF)
    Case 2
        ConsoleWrite("Error:  No Object" & @CRLF)
EndSwitch

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]')
If @error <> 0 Then
    ConsoleWrite('Creating Child Node:  "//un:unattend/un:settings[@pass="specialize"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr('//un:unattend', 'settings', "pass", "specialize", "", "urn:schemas-microsoft-com:unattend")
EndIf

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]')
If @error <> 0 Then
    ConsoleWrite('Creating Child Node:  "//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr('//un:unattend/un:settings[@pass="specialize"]', "component", "name", "Microsoft-Windows-Deployment", "", "urn:schemas-microsoft-com:unattend")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "processorArchitecture", "x86")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "language", "neutral")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "publicKeyToken", "31bf3856ad364e35")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "versionScope", "nonSxS")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
EndIf

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous')
If @error <> 0 Then
    ConsoleWrite('Creating Child Node:  "//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous" not exist' & @CRLF)
    $Temp = _XMLCreateChildNode('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "RunSynchronous", "", "urn:schemas-microsoft-com:unattend")
EndIf

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]')
If @error <> 0 Then
    ConsoleWrite('Creating Child Node:  "//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildNodeWAttr('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous', "RunSynchronousCommand", "wcm:action", "add", "", "urn:schemas-microsoft-com:unattend")

    _XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]')
    If @error = 0 Then
        ConsoleWrite('Success creating node:  //un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]' & @CRLF)
    Else
        ConsoleWrite('Failure creating node:  //un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]' & @CRLF)
    EndIf
EndIf

$Temp = _XMLCreateChildNode('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]', "Description", "Drivers Setup", "urn:schemas-microsoft-com:unattend")
$Temp = _XMLCreateChildNode('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]', "Order", "1", "urn:schemas-microsoft-com:unattend")
$Temp = _XMLCreateChildNode('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]', "Path", "cmd /c C:\Drivers\SetupDrivers.cmd", "urn:schemas-microsoft-com:unattend")

The result is this:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="specialize">
        <component name="Microsoft-Windows-Deployment" processorArchitecture="x86" language="neutral" publicKeyToken="31bf3856ad364e35" 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"/>
            </RunSynchronous>
        </component>
    </settings>
</unattend>

And the console output:

Failure creating node:  //un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"]
Error creating child node: Description
//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"] does not exist.

Error creating child node: Order
//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"] does not exist.

Error creating child node: Path
//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand[@wcm:action="add"] does not exist.

The only thing wrong now is in creation of the RunSynchronousCommand[@wcm:action="add"] node. It's there in the file, but I can't get it to recognize that node exits. Is there something weird about having "wcm:" in an attribute name? Do namespaces work the same with an attribute as they do with a node?

Anyway, everything else works except recognizing that node creation. Maybe somebody smarter in XML than me can enlighten us both.

:-)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This will create the entire xml from scratch, no copying a template.

#include "_XMLDOMWrapper.au3"

$debugging = True

Global $SYSPREPFile = @ScriptDir & "\Test2.xml"
Global $sNamespace = 'urn:schemas-microsoft-com:unattend'

;Create file, overwrite if it already exists
_XMLCreateFile($SYSPREPFile, 'unattend', true)

;Open the file we just created
_XMLFileOpen($SYSPREPFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"')
Switch @error
    Case 1
    ConsoleWrite("Error: Parse Error" & @CRLF)
    Case 2
    ConsoleWrite("Error: No Object" & @CRLF)
EndSwitch

;Set namespace for root node
_XMLSetAttrib('unattend','xmlns',$sNamespace)

;Create empty servicing node
_XMLCreateRootChild ('servicing',"", $sNamespace)

;Create root child node with attributes
_XMLCreateRootNodeWAttr ('settings', 'pass', 'specialize','',$sNamespace)

;Create component node attributes and respective values
Dim $aAttributes[7] = ["Microsoft-Windows-Deployment","processorArchitecture","language","publicKeyToken","versionScope","xmlns:wcm","xmlns:xsi"]
Dim $aValues[7] = ["","x86","neutral","31bf3856ad364e35","nonSxS","http://schemas.microsoft.com/WMIConfig/2002/State","http://www.w3.org/2001/XMLSchema-instance"]
_XMLCreateChildWAttr ('//un:settings', 'component', $aAttributes, $aValues, '', $sNamespace);

;Create RunSynchronous node
_XMLCreateChildNode ('//un:settings/un:component', 'RunSynchronous', "", $sNamespace )

;Create 1st RunSynchronousCommand node
_XMLCreateChildWAttr ('//un:settings/un:component/un:RunSynchronous', 'RunSynchronousCommand', 'wcm:action', 'add', '', $sNamespace)

;Add subnodes to 1st RunSynchronousCommand node
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[1]', 'Description', "Drivers Setup", $sNamespace)
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[1]', 'Order', "1", $sNamespace)
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[1]', 'Path', "cmd /c C:\Drivers\SetupDrivers.cmd", $sNamespace)

;Create 2nd RunSynchronousCommand node
_XMLCreateChildWAttr ('//un:settings/un:component/un:RunSynchronous', 'RunSynchronousCommand', 'wcm:action', 'add', '', $sNamespace)

;Add subnodes to 2nd RunSynchronousCommand node
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[2]', 'Description', "Drivers Setup 2", $sNamespace)
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[2]', 'Order', "2", $sNamespace)
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand[2]', 'Path', "cmd /c C:\Drivers\SetupDrivers2.exe /S", $sNamespace)

NOTE: To have your xml nicely formatted, put this at the end of your script:

_XMLTransform("", "", "")

Edited by weaponx
Link to comment
Share on other sites

Thanks for the help, weaponx!

But I don't understand the issue with identifying the RunSynchronousCommand[@wcm:action="add"] node. Your code avoids the issue by using the index instead of an attribute value to ID the node. My code seemed to create the node correctly, but then couldn't recognize it using the attribute, and I still don't see why.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you for your help

Weaponx, I am not sure that the Sysprep Windows 7 may interpret this change of syntax in the command "RunSynchronousCommand".

PsaltyDS, I confirms your observation, but when you reminders code execution, data are integrated without error. Another problem is when there are two sections "RunSynchronousCommand or more that's what it gives:

<component name="Microsoft-Windows-Deployment" processorArchitecture="x86" language="neutral" publicKeyToken="31bf3856ad364e35" 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">
                    <Description>iOSDInstall Setup</Description>
                    <Order>1</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                    <Description>iOSDInstall Setup</Description>
                    <Order>2</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                    <Description>iOSDInstall Setup</Description>
                    <Order>3</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                </RunSynchronousCommand>
                <RunSynchronousCommand wcm:action="add">
                    <Description>iOSDInstall Setup</Description>
                    <Order>2</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                    <Description>iOSDInstall Setup</Description>
                    <Order>3</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                </RunSynchronousCommand>
                <RunSynchronousCommand wcm:action="add">
                    <Description>iOSDInstall Setup</Description>
                    <Order>3</Order>
                    <Path>cmd /c C:\Drivers\iOSDInstall.bat</Path>
                </RunSynchronousCommand>
                <RunSynchronousCommand wcm:action="add"/>
            </RunSynchronous>
        </component>
Link to comment
Share on other sites

Weaponx gave exactly the right way to deal with that, using the 1-based index to address multiple instances of the same element name. So they are RunSynchronousCommand[1], RunSynchronousCommand[2], etc. If you don't know the index of the new node you are about to create, do _XMLGetNodeCount() first, then create the element, then refer to it this way when configuring it:

'.../RunSynchronousCommand[' & $iCount + 1 & ']'

Notice that completely drops the use of the wcm:action="add" attribute for identifying the element and substitutes the index instead. This gives you what you need to do your file.

:-)

For merely academic purposes of my own education, I would still like to know: Why didn't 'RunSynchronousCommand[@wcm:action="add"]' work in identifing the element when it certainly existed? Is there something wrong with that attribute name? Like maybe they're not supposed to have namespaces (namespace belongs with the element, not the attribute)?

I don't know, I'm just asking.

:D

Edit: Still learning. Should have been saying "element" vice "node". The elements and their attributes are all "nodes". Also, since a node can have a namespace, an attribute can have a namespace, so that shouldn't have been a problem. So says O'Reilly's XML In A Nutshell.

:huggles:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi Weaponx,

:D , I am really confused because while reading your code and translating the comments in frensh, I was expecting to find something like this:

<component Microsoft-Windows-Deployment="" processorArchitecture="x86" language="neutral" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" ...>

___<RunSynchronous>

______<RunSynchronousCommand[1] wcm:action="add">

_________<Description>Drivers Setup</Description>

_________<Order>1</Order>

_________<Path>cmd /c C:\Drivers\SetupDrivers.cmd</Path>

______</RunSynchronousCommand[1]>

______<RunSynchronousCommand[2] wcm:action="add">

_________<Description>Drivers Setup 2</Description>

_________<Order>2</Order>

_________<Path>cmd /c C:\Drivers\SetupDrivers2.exe /S</Path>

______</RunSynchronousCommand[2]>

___</RunSynchronous>

</component>

Like what not to be limited to read, but test is better....

To increment the serial number, I had already begun to use:

$NodeCount = _XMLGetNodeCount('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]', "", 1)

It remains for me to assemble it all ...

Weaponx still sorry to have misunderstood without testing ... :huggles:::D

Thank you to you both ...

Best Regards,

NDTC

Link to comment
Share on other sites

The assembly code looks like this and it works fine ... Thank you!

#include <_XMLDomWrapper.au3>

Global $SYSPREPFile = @ScriptDir & "\Unattend.xml"

_XMLFileOpen($SYSPREPFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"')
Switch @error
    Case 1
        ConsoleWrite("Parse Error" & @CRLF)
        Exit(1)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
        Exit(1)
EndSwitch

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr('//un:unattend', 'settings', "pass", "specialize", "", "urn:schemas-microsoft-com:unattend")
EndIf
$XMLRootPath = '//un:unattend/un:settings[@pass="specialize"]'
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]" not exist' & @CRLF)
    $Temp = _XMLCreateChildWAttr('//un:unattend/un:settings[@pass="specialize"]', "component", "name", "Microsoft-Windows-Deployment", "", "urn:schemas-microsoft-com:unattend")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "processorArchitecture", "x86")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "language", "neutral")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "publicKeyToken", "31bf3856ad364e35")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "versionScope", "nonSxS")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State")
    _XMLCreateAttrib('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
 EndIf
_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous')
If @error <> 0 Then
    ConsoleWrite('"//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous" not exist' & @CRLF)
    $Temp = _XMLCreateChildNode ('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]', "RunSynchronous", "", "urn:schemas-microsoft-com:unattend")
EndIf

_XMLSelectNodes('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]')
If @error <> 0 Then
    $NodeCount = 0
Else
    $NodeCount = _XMLGetNodeCount('//un:unattend/un:settings[@pass="specialize"]/un:component[@name="Microsoft-Windows-Deployment"]/un:RunSynchronous/un:RunSynchronousCommand [@wcm:action="add"]', "", 1)
EndIf

;Create 1st RunSynchronousCommand node
_XMLCreateChildWAttr ('//un:settings/un:component/un:RunSynchronous', 'RunSynchronousCommand', 'wcm:action', 'add', '', "urn:schemas-microsoft-com:unattend")

;Add subnodes to 1st RunSynchronousCommand node
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 1 & ']', 'Description', "Drivers Setup"& $NodeCount + 1, "urn:schemas-microsoft-com:unattend")
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 1 & ']', 'Order', $NodeCount + 1, "urn:schemas-microsoft-com:unattend")
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 1 & ']', 'Path', "cmd /c C:\Drivers\SetupDrivers1.cmd", "urn:schemas-microsoft-com:unattend")

;Create 2nd RunSynchronousCommand node
_XMLCreateChildWAttr ('//un:settings/un:component/un:RunSynchronous', 'RunSynchronousCommand', 'wcm:action', 'add', '', "urn:schemas-microsoft-com:unattend")

;Add subnodes to 2nd RunSynchronousCommand node
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 2 & ']', 'Description', "Drivers Setup "& $NodeCount + 2, "urn:schemas-microsoft-com:unattend")
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 2 & ']', 'Order', $NodeCount + 2, "urn:schemas-microsoft-com:unattend")
_XMLCreateChildNode ('//un:settings/un:component/un:RunSynchronous/un:RunSynchronousCommand['& $NodeCount + 2 & ']', 'Path', "cmd /c C:\Drivers\SetupDrivers2.exe /S", "urn:schemas-microsoft-com:unattend")
Exit

It could still be optimized by using more variables, but it works ...

Thank's to you both.

Link to comment
Share on other sites

Hi,

I have an another problem with this script:

Since Thusday, if XML have this header: "<?xml version="1.0" encoding="utf-8"?>", Script failed.

Debug = True
Error opening specified file: C:\Users\Thomas\Programmation\AutoIT\iOSDAutoDrivers\_Temp\Unattend.xml\Unattend.xml
The transition from current encoding to specified encoding not supported.

Parse Error

If i replace by this header "<?xml version="1.0"?>" the script run perfectly.

Have you an idea?

Link to comment
Share on other sites

Does your French language support require you to use utf-16, ISO-8859-1, or maybe ISO-8859-15 for extended characters?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Does your French language support require you to use utf-16, ISO-8859-1, or maybe ISO-8859-15 for extended characters?

:D

Whaaw

I don't know ...

But what I don't understand is that it worked Wednesday ...

I did another test with the following header <?xml version="1.0" encoding="UTF-16"?> and it's runing, but the file Unattend Windows 7 is "UTF-8" and not 16 ...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...