Jump to content

Recommended Posts

Posted

Hi folks,

I'm trying to use the _XMLDomWrapper UDF to create an XML answer file that can be used to configure Win7 regional settings. I have a VBScript that does what I need, however, I wanted to perform the exact same thing using an AutoIt script - if nothing else for my own learning. I'm not having much luck with it though, mainly because I haven't a clue how to make this work properly.

Here's the VBScript that works:

' set the script directory
On Error Resume Next
sScriptDir = empty
sScriptDir = WScript.ScriptFullName
sScriptDir = Left(sScriptDir, InStrRev(sScriptDir, "\"))
'Set the GeoID.xml file path
sGeoIDXml=sScriptDir & "GeoID.xml"
'Call the routine
CreateXML "242"
Sub CreateXML(GeoID)
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
  
Set objRoot = xmlDoc.createElement("gs:GlobalizationServices")
xmlDoc.appendChild objRoot
objRoot.setAttribute "xmlns:gs","urn:longhornGlobalizationUnattend"
objRoot.appendChild xmlDoc.createComment("User List ")
 
Set objRecord = xmlDoc.createElement("gs:UserList")
objRoot.appendChild objRecord
  
Set objName = xmlDoc.createElement("gs:User")
objRecord.appendChild objName
objName.setAttribute "UserID","Current"
objName.setAttribute "CopySettingsToDefaultUserAcct","true"
 
objRoot.appendChild xmlDoc.createComment("location ")
 
Set objRecord = xmlDoc.createElement("gs:LocationPreferences")
objRoot.appendChild objRecord
  
Set objName = xmlDoc.createElement("gs:GeoID")
objRecord.appendChild objName
objName.setAttribute "Value",GeoID
 
xmlDoc.Save sGeoIDXml
End Sub

Here's the XML file that the VBScript generates:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
  <!--User List -->
  <gs:UserList>
    <gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" />
  </gs:UserList>
  <!--location -->
  <gs:LocationPreferences>
    <gs:GeoID Value="242" />
  </gs:LocationPreferences>
</gs:GlobalizationServices>

Here's my (lame) attempt at coding something that works using AutoIt:

#include <_XMLDomWrapper.au3>
;~ Global $sPath = @ScriptDir & "\GEOID_test.xml"
Global $sRootNode = "gs:GlobalizationServices"
;~ _XMLCreateFile($sPath, $sRootNode, True)
;~ _XMLFileOpen($sPath)
;_XMLCreateAttrib($sRootNode, 'xmlns:gs="urn:longhornGlobalizationUnattend"')
;~ _XMLSetAttrib($sRootNode, "xmlns:gs", "urn:longhornGlobalizationUnattend")
;_XMLCreateAttrib("xmlns:gs", "urn:longhornGlobalizationUnattend")
$sFile=@ScriptDir&"\dd.xml"
 
;_XMLCreateFile($sFile, $sRootNode, True)
_XMLCreateFile($sFile, $sRootNode, True)
    _XMLFileOpen($sFile)
_XMLSetAttrib($sRootNode, "xmlns")
;_XMLCreateRootChild("config")
_XMLCreateRootChild("gs:UserList")

Please can you gurus out there shed some light on where I'm going wrong here?

Many thanks,

Gregor.

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
×
×
  • Create New...