应答文件 (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 specialize:大多数设置都应该添加到此处。4 specialize: Most settings should be added here. 这些设置可同时在审核模式和 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:启动审核模式后马上运行。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 部署重新 \ 封装 \ 模式= 审核设置,我们将使用它来绕过 OOBE 并将电脑启动到审核模式。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 基本映像文件) 位于具有读写权限的文件夹中,例如 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 specialize"。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 _ \ 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-部署 _ (版本),然后选择" 添加设置以传递 7 oobeSystem"。In the Windows Image pane, expand Components, right-click amd64_Microsoft-Windows-Deployment_(version), and then select Add Setting to Pass 7 oobeSystem.

    在 "答案文件" 窗格中,选择 "组件 \ 7 oobeSystem \ _ _ \In the Answer File pane, select Components\7 oobeSystem\amd64_Microsoft-Windows-Deployment_neutral\Reseal.

    Reseal 属性 窗格中的 设置 部分,选择 Mode=AuditIn the Reseal Properties pane, in the Settings section, select Mode=Audit.

  3. 准备一个 脚本 以在审核模式开始后运行。Prepare a script to run after Audit mode begins.

    在 " Windows 映像 " 窗格中,右键单击 " Amd64 _ Microsoft-部署 _ (版本) ,然后单击" 添加设置以传递 6 auditUser"。In the Windows Image pane, right-click amd64_ Microsoft-Windows-Deployment_(version) and then click Add Setting to Pass 6 auditUser.

    在 " 应答文件 " 窗格中,展开 " 组件 \ 6 auditUser" " \ _ _ \ 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 应用商店程序添加了注册表项。In this example, we add keys for the OEM Windows Store program. 使用 CMD /c REG ADD 来添加,其过程与添加脚本的过程相同。Use the same process as adding a script, using CMD /c REG ADD.

    对于 Windows 10 客户系统,你可以单独使用 OEM 应用商店 ID,也可以将它与应用商店内容修饰符 (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. 例如,你可以选择通过将消费者和商业品牌的唯一 SCM 插入这些设备来将商业设备与消费者设备区别对待。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.

    为每个要添加的注册表项添加 RunAsynchronousCommand。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 \ SampleCommandCopy 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 " 文件夹中,并将其命名为 unattend.xml。Copy the answer file into the image into the \Windows\Panther folder, and name it unattend.xml. Panther 文件夹是 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.