回應檔案 (unattend.xml)Answer files (unattend.xml)

在安裝期間,您可以使用回應檔案 () 或自動安裝檔案,以修改映射中的 Windows 設定。Answer files (or Unattend files) can be used to modify Windows settings in your images during Setup. 您也可以在第一位使用者建立帳戶並挑選其預設語言之後,建立在您的映射中觸發腳本的設定。You can also create settings that trigger scripts in your images that run after the first user creates their account and picks their default language.

Windows 安裝程式會自動搜尋 特定位置中的回應檔案,您也可以在執行 /unattend: Windows 安裝程式 ( # A0) 時,使用選項來指定要使用的自動安裝檔案。Windows Setup will automatically search for answer files in certain locations, or you can specify an unattend file to use by using the /unattend: option when running Windows Setup (setup.exe).

Windows 設定總覽Windows settings overview

雖然您可以在 [審核] 模式中設定許多 Windows 設定,但某些設定只能使用回應檔案或 Windows 設定設計工具來設定,例如新增製造商的支援資訊。While you can set many Windows settings in audit mode, some settings can only be set by using an answer file or Windows Configuration Designer, such as adding manufacturer’s support information. 回應檔案設定的完整清單 (也稱為自動安裝設定) 在自動 Windows 安裝程式參考中。A full list of answer file settings (also known as Unattend settings) is in the Unattended Windows Setup Reference.

企業可以使用群組原則來控制其他設定。Enterprises can control other settings by using Group Policy. 如需詳細資訊,請參閱 群組原則For more info, see Group Policy.

回應檔案設定Answer file settings

您可以指定要新增設定的設定階段:You can specify which configuration pass to add new settings:

  • 1 windowsPE : Windows 安裝程式安裝程式使用這些設定。1 windowsPE : These settings are used by the Windows Setup installation program. 如果您要修改現有的映射,通常可以忽略這些設定。If you’re modifying existing images, you can usually ignore these settings.

  • 4 特殊化 :您應該在這裡新增大部分的設定。4 specialize : Most settings should be added here. 這些設定會在 audit 模式的開頭和 OOBE 的開頭觸發。These settings are triggered both at the beginning of audit mode and at the beginning of OOBE. 如果您需要進行多項更新或測試設定,請再次將裝置一般化,然後在 Specialize 設定階段中新增另一個批次設定。If you need to make multiple updates or test settings, generalize the device again and add another batch of settings in the Specialize Configuration pass.

  • 6 auditUser :在您啟動 audit 模式時立即執行。6 auditUser : Runs as soon as you start audit mode.

    這是執行系統測試腳本的好時機,我們會在範例中新增 Microsoft Windows 部署 \ RunAsynchronousCommandThis is a great time to run a system test script - we'll add Microsoft-Windows-Deployment\RunAsynchronousCommand as our example. 若要深入瞭解,請參閱 將自訂腳本新增至 Windows 安裝程式To learn more, see Add a Custom Script to Windows Setup.

  • 7 oobeSystem :請謹慎使用。7 oobeSystem : Use sparingly. 這些設定大多是在使用者完成 OOBE 之後執行。Most of these settings run after the user completes OOBE. 例外狀況是 Microsoft-Windows-部署重新 \ 封裝 \ 模式= Audit 設定,我們將用它來略過 OOBE 並將電腦開機進入 audit 模式。The exception is the Microsoft-Windows-Deployment\Reseal\Mode = Audit setting, which we’ll use to bypass OOBE and boot the PC into audit mode.

    如果您的腳本需要知道使用者在 OOBE 期間所選取的語言,您會將它新增至 oobeSystem 階段。If your script relies on knowing which language the user selects during OOBE, you’d add it to the oobeSystem pass.

  • 若要深入瞭解,請參閱 Windows 安裝程式設定階段To learn more, see Windows Setup Configuration Passes.

注意

如果使用者使用內建的修復工具重設其電腦,這些設定可能會遺失。These settings could be lost if the user resets their PC with the built-in recovery tools. 若要瞭解如何在重設期間將這些設定保留在裝置上,請參閱 範例腳本:透過復原保留 Windows 設定To see how to make sure these settings stay on the device during a reset, see Sample scripts: Keeping Windows settings through a recovery.

建立和修改回應檔案Create and modify an answer file

步驟1:建立類別目錄檔案Step 1: Create a catalog file

  1. 開始 Windows 系統映射管理員Start Windows System Image Manager.

  2. 按一下 [ 檔案 > 選取 Windows 映像 ]。Click File > Select Windows Image.

  3. 在 [ 選取 Windows 映像 ] 中,流覽並選取 (D:\install.wim) 的影像檔案。In Select a Windows Image , browse to and select the image file (D:\install.wim). 接下來,選取 Windows 版本,例如 Windows 10 專業版,然後按一下 [確定]Next, select an edition of Windows, for example, Windows 10 Pro, and click OK. 按一下 [是] 以建立類別目錄檔案。Click Yes to create the catalog file. Windows SIM 會根據影像檔案建立檔案,並將它儲存到與影像檔相同的資料夾中。Windows SIM creates the file based on the image file, and saves it to the same folder as the image file. 此程式可能需要幾分鐘的時間。This process can take several minutes.

    類別目錄檔案就會出現在 [ Windows 映像 ] 窗格中。The catalog file appears in the Windows Image pane. Windows SIM 列出該映射中可設定的元件和套件。Windows SIM lists the configurable components and packages in that image.

    疑難排解: 如果 Windows SIM 未建立類別目錄檔案,請嘗試下列步驟:Troubleshooting: If Windows SIM does not create the catalog file, try the following steps:

    • 若要建立32位或 ARM 型裝置的類別目錄檔案,請使用32位裝置。To create a catalog file for either 32-bit or ARM-based devices, use a 32-bit device.

    • 請確定 Windows 基礎映射檔案 (\ 來源 \ 安裝 .wim ) 位於具有讀寫許可權的資料夾中,例如 USB 快閃磁片磁碟機或硬碟。Make sure the Windows base-image file (\Sources\Install.wim ) is in a folder that has read-write privileges, such as a USB flash drive or on your hard drive.

步驟2:建立回應檔案Step 2: Create an answer file

  • 按一下 [ 檔案 > 新增回應 檔案]。Click File > New Answer File.

    新的回應檔案就會出現在 [ 回應 檔案] 窗格中。The new answer file appears in the Answer File pane.

    注意 如果您開啟現有的回應檔案,系統可能會提示您將回應檔案與映射建立關聯。Note If you open an existing answer file, you might be prompted to associate the answer file with the image. 按一下 [是] 。Click Yes.

步驟3:加入新的回應檔案設定Step 3: Add new answer file settings

  1. 新增 OEM 資訊:Add OEM info:

    在 [ Windows 映像 ] 窗格中,展開 [ 元件 ],以滑鼠右鍵按一下 [Amd64]-[ _ 設定 _ (版本) ],然後選取 [ 新增設定] 以通過4特殊化In the Windows Image pane, expand Components , right-click amd64_Microsoft-Windows-Shell-Setup_(version) , and then select Add Setting to Pass 4 specialize.

    在 [ 回應 檔案] 窗格中,選取 [ 元件 4 specialize]、[ \ \ _ Microsoft Windows-Shell-安裝 _ 中立 \ OEMInformation ]。In the Answer File pane, select Components\4 specialize\amd64_Microsoft-Windows-Shell-Setup_neutral\OEMInformation.

    在 [ OEMInformation 屬性 ] 窗格的 [ 設定 ] 區段中,選取:In the OEMInformation Properties pane, in the Settings section, select:

    • 製造商 =FabrikamManufacturer=Fabrikam
    • 模型 =Notebook Model 1Model=Notebook Model 1
    • 標誌 =C:\Fabrikam\Fabrikam.bmpLogo=C:\Fabrikam\Fabrikam.bmp

    建立大小上限為120x120 圖元的32位色彩、將其儲存為 D:\AnswerFiles\Fabrikam.bmp 本機電腦上的檔案,或使用來自 USB-B 金鑰的範例: D:\ConfigSet\$OEM$\$$\System32\OEM\Fabrikam.bmpCreate a 32-bit color with a maximum size of 120x120 pixels, save it as D:\AnswerFiles\Fabrikam.bmp file on your local PC, or use the sample from the USB-B key: D:\ConfigSet\$OEM$\$$\System32\OEM\Fabrikam.bmp.

    我們將在幾個步驟中將標誌複製到 Windows 映像。We'll copy the logo into the Windows image in a few steps.

  2. 將裝置設定為自動 開機以進行稽核模式Set the device to automatically boot to audit mode:

    在 [ Windows 映像 ] 窗格中,展開 [ 元件 ],以滑鼠右鍵按一下 [ Amd64 _ Microsoft-Windows-部署 _ (版本) ],然後選取 [ 新增設定] 以通過 7 oobeSystemIn the Windows Image pane, expand Components , right-click amd64_Microsoft-Windows-Deployment_(version) , and then select Add Setting to Pass 7 oobeSystem.

    在 [ 回應 檔案] 窗格中,選取 [ 元件 \ 7 OobeSystem \ Amd64 _ Microsoft-Windows-部署 _ 中立重新 \ 封裝 ]。In the Answer File pane, select Components\7 oobeSystem\amd64_Microsoft-Windows-Deployment_neutral\Reseal.

    在 [重新 封裝屬性 ] 窗格的 [ 設定 ] 區段中,選取 [模式 =] AuditIn the Reseal Properties pane, in the Settings section, select Mode=Audit.

  3. 準備要在 Audit 模式開始之後執行的 腳本Prepare a script to run after Audit mode begins.

    在 [ Windows 映像 ] 窗格中,以滑鼠右鍵按一下 [ Amd64 _ Microsoft-Windows-部署 _ (版本]) 然後按一下 [ 新增設定] 以通過6個 auditUserIn the Windows Image pane, right-click amd64_ Microsoft-Windows-Deployment_(version) and then click Add Setting to Pass 6 auditUser.

    在 [ 回應 檔案] 窗格中,展開 [ 元件 \ 6 AuditUser \ Amd64 _ Microsoft-Windows-部署 _ 中立 \ RunAsynchronous ]。In the Answer File pane, expand Components\6 auditUser\amd64_Microsoft-Windows-Deployment_neutral\RunAsynchronous. 以滑鼠右鍵按一下 [ RunAsynchronousCommand 屬性 ],然後按一下 [ 插入新的 AsynchronousCommand ]。Right-click RunAsynchronousCommand Properties and click Insert New AsynchronousCommand.

    在 [ AsynchronousCommand 屬性 ] 窗格的 [ 設定 ] 區段中,新增下列值:In the AsynchronousCommand Properties pane, in the Settings section, add the following values:

    Path = C:\Fabrikam\SampleCommand.cmd

    Description = Sample command to run a system diagnostic check.

    Order = 1 (會決定命令的執行順序,從1開始。 ) Order = 1 (Determines the order that commands are run, starting with 1.)

  4. 新增登錄機碼。Add a registry key. 在此範例中,我們會為 OEM Windows Store 程式新增金鑰。In this example, we add keys for the OEM Windows Store program. 使用與加入腳本相同的程式 CMD /c REG ADDUse the same process as adding a script, using CMD /c REG ADD.

    針對 Windows 10 客戶系統,您可以單獨使用 OEM Store 識別碼或搭配商店內容修飾詞 (SCM) 來識別 OEM 商店的 OEM 商標。For Windows 10 Customer Systems, you may use the OEM Store ID alone or in combination with a Store Content Modifier (SCM) to identify an OEM brand for the OEM Store. 您可以藉由新增 SCM,以更細微的層級為目標客戶系統。By adding a SCM, you can target Customer Systems at a more granular level. 例如,您可以選擇將消費者和商業品牌的獨特 SCMs 插入這些裝置,以將商用裝置與消費者裝置分開。For example, you may choose to target commercial devices separately from consumer devices by inserting unique SCMs for consumer and commercial brands into those devices.

    為每個要新增的登錄機碼新增 RunAsynchronousCommands。Add RunAsynchronousCommands for each registry key to add. (以滑鼠右鍵按一下 [ RunAsynchronousCommand 屬性 ],然後按一下 [ 插入新的 AsynchronousCommand ) 。(Right-click RunAsynchronousCommand Properties and click Insert New AsynchronousCommand ).

    Path = CMD /c REG ADD HKEY_LOCAL_MACHINE\Software\OEM /v Value /t REG_SZ ABCD
    Description = Adds a OEM registry key
    Order = 2
    RequiredUserInput = false
    

如需完整的設定選項清單,請參閱自動 Windows 安裝程式參考See the Unattended Windows Setup Reference for a full list of configuration options.

步驟4:儲存回應檔案Step 4: Save the answer file

  • 儲存回應檔案,例如: D: \ AnswerFiles \BootToAudit-x64.xmlSave the answer file, for example: D:\AnswerFiles\BootToAudit-x64.xml.

    注意 Windows SIM 將不會讓您將回應檔案儲存到掛接的映射資料夾中。Note Windows SIM will not allow you to save the answer file into the mounted image folders.

步驟5:建立腳本Step 5: Create a script

由於我們已指定在步驟3中執行的腳本,現在讓我們建立該腳本。Since we specified a script to run in Step 3, let's create that script now.

  • 將下列範例腳本複製到 [記事本],並將它儲存為 D: \ AnswerFiles \ SampleCommand .cmdCopy the following sample script into Notepad, and save it as D:\AnswerFiles\SampleCommand.cmd.

    @rem Scan the integrity of system files 
    @rem (Required after removing the base English language from an image)
    sfc.exe /scannow
    
    @rem Check to see if your drivers are digitally signed, and send output to a log file.
    md C:\Fabrikam
    C:\Windows\System32\dxdiag /t C:\Fabrikam\DxDiag-TestLogFiles.txt
    

將回應檔案和腳本新增至映射Add the answer file and script to the image

步驟6:掛接映射並新增回應檔案Step 6: Mount an image and add the answer file

  1. 使用 DISM 掛接 Windows 映像。Use DISM to mount a Windows image. 若要瞭解如何掛接映射,請參閱 使用 DISM 掛接和修改 Windows 映像To learn how to mount an image, see Mount and modify a Windows image using DISM

  2. 將回應檔案複製到該映射中的 [ \ Windows \ >\panther\setupact.log ] 資料夾,並將它命名為 unattend.xml。Copy the answer file into the image into the \Windows\Panther folder, and name it unattend.xml. >\panther\setupact.log 資料夾是 Windows 搜尋回應檔案的資料夾之一。The Panther folder is one of the folders where Windows searches for an answer file. 如果資料夾不存在,請加以建立。Create the folder if it doesn’t exist. 如果有現有的回應檔案,請將它取代,或視需要使用 Windows 系統映射管理員來編輯/合併設定。If there’s an existing answer file, replace it or use Windows System Image Manager to edit/combine settings if necessary.

    MkDir c:\mount\windows\Windows\Panther
    Copy D:\AnswerFiles\BootToAudit-x64.xml  C:\mount\windows\Windows\Panther\unattend.xml
    MkDir c:\mount\windows\Fabrikam
    Copy D:\AnswerFiles\Fabrikam.bmp    C:\mount\windows\Fabrikam\Fabrikam.bmp
    Copy D:\AnswerFiles\SampleCommand.cmd    C:\mount\windows\Fabrikam\SampleCommand.cmd
    
  3. 卸載映射,並認可變更。Unmount the image, committing the changes. 例如︰For example:

    Dism /Unmount-Image /MountDir:"C:\mount\windows" /Commit
    

    其中 C 是包含已掛接映射之磁片磁碟機的磁碟機號。where C is the drive letter of the drive that contains the mounted image.

    此程序可能需要幾分鐘的時間。This process may take several minutes.

當您套用 映射時,Windows 將會處理您的自動安裝檔案,並根據您在自動安裝中指定的內容來設定您的設定。When you apply your image, Windows will process your unattend file and will configure your settings based on what you specified in the unattend.