如何写XML文件(Autounattend.xml)
本帖最后由 hanz_200 于 2014-6-6 22:33 编辑使用UDF为:_XMLDomWrapper.au3
引用版本为:好吧!我发现了这个
2010版,作者是修改了!但是没完善,是为完成品,无法正常使用的!
_XMLFileOpen
_XMLLoad ...
heavenm 发表于 2013-6-8 02:57 http://www.autoitx.com/images/common/back.gif
http://www.autoitx.com/forum.php?mod=viewthread&tid=38792&highlight=%5C_XMLDomWrapper.au3#include <_XMLDomWrapper.au3>
$sXMLFile = "Autounattend.xml"
$result = _XMLFileOpen($sXMLFile, 'xmlns:un="urn:schemas-microsoft-com:unattend"')
If $result = 0 Then Exit
$path = '//un:unattend/un:settings[@pass="windowsPE"]/un:component[@name="Microsoft-Windows-Setup"]/un:UserData/un:ProductKey/un:Key'
$path1 = '//un:unattend/un:settings[@pass="windowsPE"]/un:component[@name="Microsoft-Windows-Setup"]/un:UserData/un:ProductKey'
$Key=_GetFirstValue($path)
MsgBox(0,"Key",$Key)
_XMLUpdateField($path1,"Key","xxxxx-xxxxx-xxxxx-xxxxx-xxxx")
; 无法更新值
Func _GetFirstValue($node)
$ret_val = _XMLGetValue($result,$node)
If IsArray($ret_val) Then
Return ($ret_val)
Else
Return SetError(1,3,0)
EndIf
EndFuncAutounattend.xml 文件为:<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserData>
<ProductKey>
<Key>TNH8J-KG84C-TRMG4-FFD7J-VH4WX</Key>
<WillShowUI>OnError</WillShowUI>
</ProductKey>
<AcceptEula>false</AcceptEula>
<FullName>Lenovo</FullName>
<Organization>Lenovo</Organization>
</UserData>
<UseConfigurationSet>true</UseConfigurationSet>
</component>
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SetupUILanguage>
<WillShowUI>Always</WillShowUI>
</SetupUILanguage>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-Store-Client-UI" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StoreContentModifier>Lenovo3_Idea</StoreContentModifier>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="AMD64" 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>TNH8J-KG84C-TRMG4-FFD7J-VH4WX</ProductKey>
<OEMName>Lenovo</OEMName>
<OEMInformation>
<Manufacturer>Lenovo</Manufacturer>
<SupportURL>http://support.lenovo.com</SupportURL>
<HelpCustomized>true</HelpCustomized>
<Model>Lenovo Product</Model>
<Logo>c:\windows\System32\OOBE\info\Lenovo_logo.bmp</Logo>
</OEMInformation>
<Themes>
<DesktopBackground>%WINDIR%\Web\Wallpaper\Lenovo\LenovoWallPaper.jpg</DesktopBackground>
<ThemeName>Lenovo</ThemeName>
</Themes>
</component>
<component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Home_Page>http://www.lenovo.com</Home_Page>
<Help_Page>http://support.lenovo.com</Help_Page>
<UserAgent>LENW8</UserAgent>
</component>
<component name="Microsoft-Windows-HelpAndSupport" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HelpAndSupport>
<Logo>c:\windows\System32\OOBE\info\Lenovo_Help_logo.png</Logo>
<LogoURL>http://support.lenovo.com</LogoURL>
<Manufacturer>Lenovo</Manufacturer>
<TileColor>0</TileColor>
<SearchContent>true</SearchContent>
</HelpAndSupport>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OEMName>Lenovo</OEMName>
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>C:\WINDOWS\CLENOVO.CMD</CommandLine>
<Description>Remove Firstboot</Description>
<Order>89</Order>
</SynchronousCommand>
</FirstLogonCommands>
</component>
<component name="Microsoft-Windows-PerfCenterCPL" processorArchitecture="AMD64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<WindowsExperienceIndexOemInfo>
<HardwareUpgradeURL>http://www.lenovo.com</HardwareUpgradeURL>
<Logo>c:\windows\System32\OOBE\info\Lenovo_Performance_logo.bmp</Logo>
</WindowsExperienceIndexOemInfo>
</component>
</settings>
<cpi:offlineImage cpi:source="catalog:c:/users/kenpacq/desktop/images and clg files/Predeveloperpreview.clg" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
寻求帮助!可以获得Key,但是无法写入! 这个如何写?没有人知道吗? 先用好论坛的搜索功能吧!
还有不告诉_XMLDomWrapper.au3的版本(或者autoit的版本),不太好搞啊! 标准的写没问题,遇到这种特殊的没办法了!
论坛上貌似也没有这个解决方法! 貌似没有人解答啊! 本帖最后由 shqf 于 2014-7-1 22:14 编辑
_XMLDomWrapper.au3中的$_XMLUDFVER = "1.0.3.98",在heavenm修改的基础上,再将_XMLDomWrapper.au3库中的所有_XMLSaveDoc($strFile)语句替换成_XMLSaveDoc($objDoc,$strFile),然后#include <_XMLDomWrapper.au3>
$sXMLFile = "Autounattend.xml"
$result = _XMLFileOpen($sXMLFile, 'xmlns:un="urn:schemas-microsoft-com:unattend"')
If $result = 0 Then Exit
$path = '//un:unattend/un:settings[@pass="windowsPE"]/un:component[@name="Microsoft-Windows-Setup"]/un:UserData/un:ProductKey/un:Key'
MsgBox(0, "Key", _GetFirstValue($path))
_XMLUpdateField($result, $path, "xxxxx-xxxxx-xxxxx-xxxxx-xxxx")
MsgBox(0, "Key", _GetFirstValue($path))
ShellExecute("notepad.exe", $sXMLFile)
Func _GetFirstValue($node)
$ret_val = _XMLGetValue($result, $node)
If IsArray($ret_val) Then
Return ($ret_val)
Else
Return SetError(1, 3, 0)
EndIf
EndFunc ;==>_GetFirstValue就能成功。
是_XMLDomWrapper.au3升级的后遗症,原先的库函数中许多函数$objDoc是自动引用的,升级后改为要写明。但_XMLSaveDoc($strFile)语句遗漏了。
3.3.9.0中的ACN_XMLDomWrapper.au3,其$_XMLUDFVER = "1.0.3.98",问题同样存在。建议修改一下吧。不知后面的版本如何。 如果能出个XML的就好了现在好多都是用XML写的控件
页:
[1]