找回密码
 加入
搜索
查看: 8621|回复: 6

[效率算法] 如何写XML文件(Autounattend.xml)

[复制链接]
发表于 2014-6-4 17:28:33 | 显示全部楼层 |阅读模式
本帖最后由 hanz_200 于 2014-6-6 22:33 编辑

使用UDF为:_XMLDomWrapper.au3
引用版本为:
好吧!我发现了这个
2010版,作者是修改了!但是没完善,是为完成品,无法正常使用的!
_XMLFileOpen
_XMLLoad ...
heavenm 发表于 2013-6-8 02:57

http://www.autoitx.com/forum.php ... C_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[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Autounattend.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,但是无法写入!
 楼主| 发表于 2014-6-6 17:03:08 | 显示全部楼层
这个如何写?没有人知道吗?
发表于 2014-6-6 17:10:39 | 显示全部楼层
先用好论坛的搜索功能吧!
还有不告诉_XMLDomWrapper.au3的版本(或者autoit的版本),不太好搞啊!
 楼主| 发表于 2014-6-6 22:34:43 | 显示全部楼层
标准的写没问题,遇到这种特殊的没办法了!
论坛上貌似也没有这个解决方法!
 楼主| 发表于 2014-6-30 20:06:00 | 显示全部楼层
貌似没有人解答啊!
发表于 2014-7-1 18:35:20 | 显示全部楼层
本帖最后由 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[1])
        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",问题同样存在。建议修改一下吧。不知后面的版本如何。
发表于 2014-7-11 09:59:42 | 显示全部楼层
如果能出个XML的就好了现在好多都是用XML写的控件
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-6 00:49 , Processed in 0.077494 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表