從 Office 自訂工具自訂檔案檢視 XML 內容

 

適用版本: Office 2010

上次修改主題的時間: 2016-11-29

管理員可使用 Office 自訂工具 (OCT) 自訂 Microsoft Office 2010 的安裝。自訂設定會儲存於安裝程式自訂檔 (.msp 檔) 中,該檔案使用可延伸標記語言 (XML) 格式。本文包含 Microsoft Visual Basic 指令碼範例,管理員可用以檢視儲存在安裝程式自訂 .msp 檔中的設定。

本文內容:

  • Windows Script Host 概觀

  • ExtractOctXml.vbs 指令碼範例

  • 執行指令碼

  • 檢視 .msp 自訂檔的 XML 內容

Windows Script Host 概觀

若要執行指令碼,請使用 Windows Script Host (WSH),這是和語言無關而與 Windows 指令碼引擎相關之 Scripting Host。

若要從 Windows 執行指令碼,會從 WScript.exe 提供 Windows 的對話方塊以設定指令碼屬性;若要從命令提示字元執行指令碼,會從 CScript.exe 提供命令列參數以設定指令碼屬性。

WSH 提供指令碼的拖曳支援。這表示您可以將檔案拖到 WSH 指令碼上。檔案名稱會轉換成命令列上的引數。

如需 WSH 的相關資訊,請參閱 MSDN 網站上的下列資源:

ExtractOctXml.vbs 指令碼範例

下列各節提供 Visual Basic 指令碼 ExtractOctXml.vbs 範例,以及使用指令碼從 OCT .msp 自訂檔擷取 XML 中繼資料的說明。

若要儲存指令碼範例,請開啟文字編輯器 (例如記事本),然後將本節中的指令碼程式碼複製並貼到檔案中。請將指令碼檔案儲存成 ExtractOctXml.vbs。

' Utility to extract the metadata from an Office 2010 customization patch 
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) Microsoft Corporation. All rights reserved.
'
Option Explicit

Const msiOpenDatabaseModePatchFile = 32
Const msiOpenDatabaseModeReadOnly     = 0
Const msiReadStreamBytes = 1

Const ForWriting = 2
Const TristateTrue = -1

Dim pathOCT_Patch 'As String
Dim pathMetadataXml 'As String
Dim sMetadata 'As String
Dim wshShell 'As Wscript.Shell
Dim fso 'As FileSystemObject
Dim fileOutput 'As File
Dim sErrSection ' As String


sErrSection = "ArgCheck"
' Check arg count, and display help if argument not present or contains ?
Dim argCount:argCount = Wscript.Arguments.Count
If argCount > 0 Then If InStr(1, Wscript.Arguments(0), "?", vbTextCompare) > 0 Then argCount = 0
If (argCount = 0) Then
    Wscript.Echo "Office 2010 OCT Metadata Extract utility" & _
        vbNewLine & " You must supply the location of the Office 2010 customization patch " & _
        vbNewLine & _
        vbNewLine & "Copyright (C) Microsoft Corporation.  All rights reserved."
    Wscript.Quit 1
Else
    pathOCT_Patch = Trim(Wscript.Arguments(0))
End If


sErrSection = "FSO"
' Create FileSystemObject and verify file exists
Set fso = CreateObject("Scripting.FileSystemObject") : CheckError
If Not fso.FileExists(pathOCT_Patch) Then Err = 2 : CheckError


sErrSection = "WI"
' Connect to Windows Installer object
On Error Resume Next
Dim wi : Set wi = Nothing
Set wi = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError


sErrSection = "Read Metadata"
' Open OCT patch and read the metadata stream
Dim wiStorage, vw, rec
Set wiStorage = wi.OpenDatabase(pathOCT_Patch, msiOpenDatabaseModePatchFile) : CheckError
Set vw = wiStorage.OpenView("SELECT * FROM _Streams WHERE `Name`='metadata' ") : CheckError
vw.Execute
Set rec = vw.Fetch
If Not rec Is Nothing Then
    sMetadata = rec.ReadStream(2, rec.DataSize(2), msiReadStreamBytes)
Else
    Wscript.Echo "No Metadata stream was found in this file: " & pathOCT_Patch
    Wscript.Quit 2
End If

Set wiStorage = Nothing
Set rec = Nothing: Set vw = Nothing
Set wi = Nothing


sErrSection = "Write Metadata"
' Write the metadata stream to a temp file
Set wshShell = CreateObject("WScript.Shell") : CheckError
pathMetadataXml = wshShell.ExpandEnvironmentStrings("%temp%") & "\" & fso.GetFileName(pathOCT_Patch) & ".xml"
Set fileOutput = fso.OpenTextFile(pathMetadataXml, ForWriting, True, -1) : CheckError
fileOutput.WriteLine sMetadata 
fileOutput.Close

Set fileOutput = Nothing: Set fso = Nothing

sErrSection = "Show Metadata"
' Launch Metadata in IE
wshShell.Run "iexplore.exe " & pathMetadataXml 

    
    
Sub CheckError
Dim sMsg, errRec
    If Err = 0 Then Exit Sub
    sMsg = sErrSection & vbNewLine & Err.Source & " " & Hex(Err) & ": " & Err.Description
    If Not wi Is Nothing Then
    Set errRec = wi.LastErrorRecord
        If Not errRec Is Nothing Then sMsg = sMsg & vbNewLine & errRec.FormatText
    End If
    Wscript.Echo sMsg
    Wscript.Quit 2
End Sub

Sub NoMetadata
End Sub

執行指令碼

ExtractOctXml.vbs 檔案可以儲存在您電腦的任意處。若要使用 ExtractOctXml.vbs 指令碼,您可以拖曳您要查看其所設定的 OCT .msp 自訂檔,然後將其置於指令碼上。指令碼會將中繼資料 XML 擷取到使用者的暫存資料夾而成為 <OCT 更新的名稱>.xml (例如,Access.MSP.xml)。如此即會將 XML 檔案傳送到 Internet Explorer 進行檢視。

執行指令碼

  1. 使用 Windows 檔案總管開啟包含 ExtractOctXml.vbs 檔的資料夾。

  2. 將您要檢視的安裝程式自訂 .msp 檔複本,拖放到 Windows 檔案總管視窗中所顯示的 ExtractOctXml.vbs。

  3. XML 檔案開啟之後,即可展開及收合各區域,以檢視包含在 .msp 自訂檔案中的設定。

    Access.MSP.xml metadata.xml 檔案的 <UserSettings> 元素包含了在 .msp 自訂檔案中設定的使用者設定,而 Access.MSP.xml metadata.xml 檔案的 <Options> 元素則包含了與功能狀態相關的設定。

使用命令列執行指令檔

  1. 依序按一下 [開始]、[執行],然後輸入 cmd

  2. 在命令提示字元視窗中輸入:

    cscript <指令碼路徑> \ExtractOCTXml.vbs <OCT MSP 路徑及檔案名稱>

    - 或 -

    wscript <指令碼路徑> \ExtractOCTXml.vbs <OCT MSP 路徑及檔案名稱>

    XML 檔案會載入 Internet Explorer 加以檢視。

檢視 .msp 自訂檔案的 XML 內容

OCT 會使用設定 (.opax) 檔案填入 OCT 的 [修改使用者設定] 使用者介面,並在安裝期間新增適合的登錄機碼與值。Office 2010 設定 .opax 檔案儲存在 Admin 資料夾中,此資料夾位於您 Office 2010 原始程式檔位置或 CD 的根目錄。

下表說明 .msp metadata.xml 檔案中包含的頂層區段。

區段 描述

<Customization platform - baseFolder>

提供 .msp 自訂檔案名稱及路徑資訊。這些元素由程式碼於內部使用。它們不會呈現實際的自訂。

<Product id>

提供關於本機安裝來源封裝、安裝狀態 (例如「必須安裝」)、語言 MUI 封裝、產品識別碼、功能及識別碼、捷徑,以及可升級的應用程式。

這些元素由程式碼於內部使用。它們不會呈現實際的自訂。

<SecurityApps>

列出可以具有特定安全性位置的應用程式,如 OCT 中 [安裝程式\Office 安全性設定] [新增下列路徑到信任的位置清單] 區域內之下拉式清單中所指出的位置。

這些元素由程式碼於內部使用。它們不會呈現實際的自訂。

<SecurityAppSettings>

列出 OCT 中出現在 [安裝程式\Office 安全性設定] 區域中的安全性設定。此清單中的自訂內容會出現在稍後的 <SecuritySettings> 元素中。

這些元素由程式碼於內部使用。它們不會呈現實際的自訂。

<SecurityPossibleSettingValues>

列出可供 <SecurityAppSettings> 使用的安全性選項。

這些元素由程式碼於內部使用。它們不會呈現實際的自訂。

<GlobalSettings>

提供 OCT 的 [安裝程式\修改安裝程式內容] 區段中所找到的安裝程式屬性相關資訊。

<UserSettings>

提供 OCT 的 [功能\修改使用者設定] 區段中所設定之任何設定的相關資訊以及登錄機碼資料。

<File>

提供使用 OCT 中 [其他內容\新增檔案] 或 [移除檔案] 選項,新增或移除之任何檔案的相關資訊。

<Registry>

提供使用 OCT 中 [其他內容\新增登錄項目] 或 [移除登錄項目] 選項,新增或移除之任何登錄機碼的相關資訊。

<Shortcuts>

提供使用 OCT 中 [其他內容\設定捷徑] 選項所新增之捷徑的相關資訊。

<Install>

提供 OCT 中 [安裝程式\安裝位置及公司/組織名稱]、[安裝程式\其他網路來源] 及 [安裝程式\授權及使用者介面] 等選項中所找到之安裝設定的相關資訊。

<ChildInstalls>

提供 OCT 中 [安裝程式\新增安裝並執行程式] 選項內所找到之其他後續安裝動作的相關資訊。

<Options>

包含與應用程式功能狀態相關的設定。

<SecuritySettings>

提供使用 OCT 的 [安裝程式\Office 安全性區段\預設安全性設定] 區段,對預設安全性設定所進行之變更的相關資訊。

<SecurityTrustedLocations>

提供在 OCT 中 [安裝程式\Office 安全性設定] 選項內所新增之信任位置 (在 [新增下列路徑到信任的位置清單]) 的相關資訊。

<SecurityCertificates>

提供在 OCT 中 [安裝程式\Office 安全性設定] 選項內所新增之憑證 (在 [新增下列數位憑證到信任的發行者清單]) 的相關資訊。

<Outlook>

提供在 OCT 的 [Outlook] 選項中所進行之 [Outlook 設定檔] 自訂的相關資訊。

下列範例顯示如何在所產生的 XML 檔案 (本例中為 Access.MSP.xml) 內找到設定,此 XML 檔案會在您執行 ExtractOctXml.vbs 指令碼並搭配 OCT .msp 自訂檔案時,開啟於 Internet Explorer 中。

範例

此範例使用 Office 2010 .msp 自訂檔案。只安裝了 Microsoft Access 2010 並啟用了 Microsoft Office Access 2007 檔案格式。Access 的 [預設檔案格式] 使用者設定,位於 OCT 的 [修改使用者設定] 區段之 [Microsoft Office Access 2010\其他] 節點內。

您可以搜尋自訂 metadata.xml 檔 (Access.MSP.xml) 中的登錄機碼或值 (例如,Default file format)。在本例中,搜尋 “default file format” 會將您帶到 Access.MSP.xml metadata.xml 檔案的下列區段:

<AddRegistries>

<AddRegistry root="HKCU" key="software\microsoft\office\14.0\access\settings" name="default file format" emptykey="false" flags="0" type="2" value="12" guid="{39478C45-8DBA-403C-B4BB-1F1D07CE85D7}" />

請使用文字編輯器 (例如記事本) 開啟 Access 2010 .opax 設定檔 access14.opax (位於 Admin 資料夾中 Office 2010 原始檔案位置的根目錄)。請搜尋 DefaultFileFormat 字串 (它對應到 [預設檔案格式] 使用者設定)。如此會顯示 access14.opax 檔案的下列區段:

<policy name="L_DefaultFileFormat" class="User" displayName="$(string.L_DefaultFileFormat)" explainText="$(string.L_DefaultFileFormatExplain)" presentation="$(presentation.L_DefaultFileFormat)" key="software\policies\microsoft\office\14.0\access\settings">

<parentCategory ref="L_Miscellaneous" />

<supportedOn ref="windows:SUPPORTED_WindowsVista" />

<elements>

<enum id="L_empty87" valueName="Default File Format">

<item displayName="$(string.L_Access2007)">

<value>

<decimal value="12" />

</value>

</item>

<item displayName="$(string.L_Access20022003)">

<value>

<decimal value="10" />

</value>

</item>

<item displayName="$(string.L_Access2000)">

<value>

<decimal value="9" />

</value>

</item>

</enum>

</elements>

</policy>

您可以利用此使用者設定資訊,確認設定的登錄機碼 (在本例中為 software\policies\microsoft\office\14.0\access\settings) 以及可能的登錄值。Default File Format 值為 12 會將預設檔案格式設定成 Access 2007;而 Default File Format 為 10 則會將預設檔案格式設定成 Access 2002-2003。

使用來自 .opax 檔案的資訊,即可看到 Default File Format 機碼的值為 12,其會將預設檔案格式設定為 Access 2007。

下列摘錄會顯示本例中 Access.MSP.xml 檔案的 <Options> 區段中所列出之部分 Access Option id 值:

<Option id="ACCESSFiles" installState="3" />

<Option id="Access_PIA" installState="3" />

<Option id="AccessWizards" installState="3" />

<Option id="DeveloperWizards" installState="3" />

<Option id="AccessHelpFiles" installState="3" />

<Option id="AccessTemplatesIntl" installState="3" />

如需 OptionState 識別碼的詳細資訊,請參閱<2010 Office Config.xml 檔案>中的<OptionState 元素>。