有关创建应答文件的最佳做法Best Practices for Authoring Answer Files

建议创建答案文件的以下最佳方案。We recommend the following best practices for creating answer files.

您可以使用多种方法来使用答案文件。There are many ways in which you can use answer files. 有关如何将答案文件与 Windows 安装程序一起使用的详细信息,请参阅 Windows 安装程序自动化概述For more information about how to use an answer file with Windows Setup, see Windows Setup Automation Overview. 有关如何将答案文件与 sysprep 工具配合使用的详细信息,请将 答案文件与 sysprep 配合使用For more information about how to use an answer file with the Sysprep tool, Using Answer Files with Sysprep. 若要详细了解如何将答案文件用于部署映像服务和管理 (DISM) ,请参阅 Dism 无人参与服务 Command-Line 选项For more information about how to use an answer file with Deployment Image Servicing and Management (DISM), see DISM Unattended Servicing Command-Line Options.

始终在 Windows SIM 中验证答案文件Always Validate Answer Files in Windows SIM

建议在 Windows 系统映像管理器 (Windows SIM) 中创建答案文件。The recommended way to author answer files is to create them in Windows System Image Manager (Windows SIM). 但是,如果使用手动创作的答案文件,则必须在 Windows SIM 中验证答案文件,以验证答案文件是否正常工作。However, if you use a manually authored answer file, you must validate the answer file in Windows SIM to verify that the answer file works.

由于可用设置和默认值有时可能会更改,因此,在重新使用时,必须重新验证答案文件。Because available settings and default values can sometimes change, you must revalidate your answer file when you reuse it.

避免不必要的设置Avoid Unnecessary Settings

您可以通过将设置的父节点插入到答案文件中引入不必要的设置。You can introduce unnecessary settings by inserting a setting's parent node into the answer file.

Windows SIM 不会在答案文件中创建空的设置。Windows SIM does not create an empty setting in an answer file. 尽管在 Windows 安装程序过程中忽略空设置,但空字符串可以扩展安装时间。Although empty settings are ignored during Windows Setup, empty strings can extend installation time. 因此,在创作答案文件时,请删除所有不需要的设置。Therefore, as you author your answer file, remove any settings that are not required.

通常,最好将组件向下展开,一直到最低级别,然后只选择那些要设置的元素。In general, it is best to expand down to the lowest level of a component and select only those elements that you intend to set. 对于默认值,除非元素是必需的元素,否则不需要包含元素。For the default value, you do not have to include the element unless it is a required element.

了解配置阶段Understand Configuration Passes

配置阶段表示不同的安装阶段。Configuration passes represent different phases of installation. 了解每个配置阶段中发生的情况对于创建答案文件非常重要。Understanding what happens during each configuration pass is very important to creating answer files. 有关详细信息,请查看 Windows 安装程序自动化概述 以及 配置阶段的工作方式For more information, review Windows Setup Automation Overview and How Configuration Passes Work.

避免创建空元素Avoid Creating Empty Elements

Windows SIM 支持在答案文件中创建空元素。Windows SIM supports creating empty elements in an answer file. 通过右键单击字符串设置类型,然后单击 " 写入空字符串 ",可以在答案文件中创建一个空元素。By right-clicking a string setting type and then clicking Write empty string , you create an empty element in the answer file. 不过,有些设置支持空元素,而有些则不支持。However, some settings support empty elements, and some do not. 在某些情况下,创建空元素将会导致 Windows 安装失败。In some cases, creating an empty element causes Windows Setup to fail. 创建空元素之前,请参阅 Windows®无人参与安装参考中的组件设置文档 (Unattend.xml) 。Before you create an empty element, see the component-setting documentation in the Windows® Unattended Setup Reference (Unattend.chm).

为每个配置阶段创建 Architecture-Specific 节Creating Architecture-Specific Sections for Each Configuration Pass

如果执行跨平台部署,请不要在一个应答文件中复制不同体系结构类型的组件。If you perform cross-platform deployments, do not duplicate components for different architecture types in a single answer file. 如果有多个组件适用于单个应答文件中的不同体系结构类型,则安装程序可能会多次应用组件中的设置,否则可能会错误地应用设置。If you have multiple components that apply to different architecture types in a single answer file, the installation program may apply settings in the components more than once, or it may apply the settings incorrectly.

对于跨平台部署,必须在答案文件中为每个配置阶段创建特定于体系结构的设置。For cross-platform deployments, you must create architecture-specific settings for each configuration pass in an answer file. 例如,对于32位预安装环境和64位目标计算机,必须在 windowsPE 配置阶段中仅指定基于 x86 的组件,并在所有其他配置阶段中仅指定基于 x64 的组件。For example, for a 32-bit preinstallation environment and a 64-bit destination computer, you must specify only x86-based components in the windowsPE configuration pass and only x64-based components in all other configuration passes.

对于64位应答文件,wow64 设置是应用程序的32位版本,适用于包括32位模式和64位模式的应用程序。For 64-bit answer files, the wow64 settings are the 32-bit versions of an app, for those apps that include both 32-bit and 64-bit modes.

提高答案文件的安全性Improve Security for Answer Files

答案文件存储了敏感数据,其中包括产品密钥、密码和其他帐户信息。Answer files store sensitive data, including product keys, passwords, and other account information. 可以遵循以下最佳做法来帮助保护此敏感数据:You can help protect this sensitive data by following these best practices:

  • 限制访问答案文件的权限。Restrict access to answer files. 根据你的环境,你可以更改访问控制列表 ( acl ) 或文件上的权限。Depending on your environment, you can change the access control lists ( ACLs ) or permissions on a file. 只有批准的帐户才能访问应答文件。Only approved accounts can access answer files.

  • 隐藏密码。Hide passwords. 若要提高答案文件的安全性,可以使用 Windows SIM 隐藏本地帐户的密码。To improve security in answer files, you can hide the passwords for local accounts by using Windows SIM. 有关详细信息,请参阅 隐藏应答文件中的敏感数据For more information, see Hide Sensitive Data in an Answer File.

  • 删除缓存的答案文件。Delete the cached answer file. 在无人参与的 Windows 安装过程中,答案文件将被缓存到计算机中。During unattended Windows installation, answer files are cached to the computer. 对于每个配置阶段,将删除缓存的答案文件中诸如域密码和产品密钥一类的敏感信息。For each configuration pass, sensitive information such as domain passwords and product keys are deleted in the cached answer file. 不过,答案文件中的其他信息仍可读取。However, other information is still readable in the answer file. 在将计算机交付给客户之前,请在 % WINDIR% \ panther 中删除缓存的答案文件。Before you deliver the computer to a customer, delete the cached answer file in %WINDIR%\panther.

    备注

    仅当在 oobeSystem 配置阶段未处理任何设置时才删除应答文件。Delete the answer file only if no settings will be processed during the oobeSystem configuration pass. OobeSystem 配置阶段会在 (OOBE) 启动之前立即处理。The oobeSystem configuration pass is processed immediately before Out-Of-Box Experience (OOBE) starts. 这通常是客户首次打开计算机时。This is typically the first time that a customer turns on the computer. 如果删除此文件夹中的应答文件,则不会处理这些设置。If you delete the answer file from this folder, those settings will not be processed.

使用数据映像或 $OEM $ 文件夹时,请勿覆盖现有文件Do Not Overwrite Existing Files When You Are Using Data Images or $OEM$ Folders

添加数据(如其他驱动程序或应用程序)时,请不要覆盖 Windows 系统文件。When you add data, such as additional drivers or applications, do not overwrite Windows system files. 覆盖系统文件会损坏计算机。Overwriting system files can corrupt your computer. 有关如何添加驱动程序和应用程序的信息,请参阅 如何创建数据映像 以及 如何管理分发共享中的文件和文件夹For information about how to add drivers and applications, see How to Create a Data Image and How to Manage Files and Folders in a Distribution Share.

使用单独的应答文件部署到多个体系结构类型Use Separate Answer Files to Deploy to Multiple Architecture Types

为要部署到的每个体系结构类型创建单独的答案文件。Create separate answer files for each architecture type that you intend to deploy to. 如果一个应答文件包含多个应用于不同体系结构类型的组件,则可能会多次应用组件设置或应用不正确。If a single answer file contains multiple components that apply to different architecture types, the component settings may be applied more than once or may be applied incorrectly.

为特定自定义项使用多个答案文件Use Multiple Answer Files for Specific Customizations

可以使用多个应答文件 ( # A0) 来创建不同的自定义集,这些自定义设置可在不同时间应用于映像。You can use multiple answer files (Unattend.xml) to create different sets of customizations that you can apply to your images at different times. 例如,你可以在 Windows 安装程序期间使用包含品牌和支持信息的一般答案文件。For example, you can use a generic answer file that contains your branding and support information during Windows Setup. 安装完成后,当你运行 Sysprep 工具时,你可以应用另一个应答文件来添加更多自定义。After installation finishes, when you run the Sysprep tool, you can apply a second answer file to add more customizations. 当必须为 Windows 映像提供服务时,可以将不同的答案文件与 DISM 一起使用。When you must service your Windows image, you can use a different answer file with DISM.

例如,可以在与 Windows 安装程序一起使用的答案文件中定义基本自定义。For example, you can define your basic customizations in an answer file that you use with Windows Setup. 安装完成后,可以将答案文件与 SysprepDISM 一起使用。After installation finishes, you can use an answer file with Sysprep or DISM. 例如,如果你想要保留在 通用化 过程中添加到安装的所有驱动程序,则可以创建用于包含 PersistAllDeviceInstalls 设置的 Sysprep 的答案文件。For example, if you want to keep all of the drivers that were added to the installation during a generalize process, you can create an answer file to use with Sysprep that contains the PersistAllDeviceInstalls setting. 可以通过运行以下命令来应用答案文件: Sysprep/generalize/unattend:answerfileYou can apply an answer file by running the following command: Sysprep /generalize /unattend:answerfile.

有关如何将答案文件与 Windows 安装程序一起使用的详细信息,请参阅 Windows 安装程序 Command-Line 选项For more information about how to use an answer file with Windows Setup, see Windows Setup Command-Line Options.

有关如何将答案文件与 sysprep 配合使用的详细信息,请参阅 sysprep Command-Line 语法For more information about how to use an answer file with Sysprep , see Sysprep Command-Line Syntax.

有关如何将答案文件与 DISM 一起使用的详细信息,请参阅 Dism 无人参与服务 Command-Line 选项For more information about how to use an answer file with DISM, see DISM Unattended Servicing Command-Line Options.

使用正确的机制向 Windows 映像添加更新Use the Correct Mechanisms to Add Updates to a Windows Image

只使用 Microsoft 支持的处理机制更新 Windows 映像。Use only the Microsoft-supported servicing mechanisms to update a Windows image.

使用 DISM 更新脱机 Windows 映像。Use DISM to update an offline Windows image. 有关详细信息,请参阅 服务脱机映像For more information, see Service an Offline Image.

在安装期间,您还可以将计算机配置为从 Windows Update 自动下载更新。During installation, you can also configure the computer to automatically download updates from Windows Update.

警告

切勿使用 $OEM$ 子文件夹或数据映像覆盖 Windows 系统文件。Never overwrite Windows system files by using $OEM$ subfolders or data images.

如果要将其他设备驱动程序添加到计算机,请使用 DISM 脱机添加这些驱动程序。If you have additional device drivers to add to a computer, add these drivers offline by using DISM. 还可以通过使用 microsoft-windows-pnpcustomizationsnonwinpemicrosoft-windows-pnpcustomizationwinpe 组件在无人参与安装中包含其他驱动程序。You can also include additional drivers in an unattended installation by using the Microsoft-Windows-PnPCustomizationsNonWinPE and Microsoft-Windows-PnPCustomizationWinPE components. 有关详细信息,请参阅 如何脱机添加和删除驱动程序For more information, see How to Add and Remove Drivers Offline.

指定语言设置Specify Language Settings

若要通过使用应答文件来更改语言,请使用 Microsoft Windows-国际核心-WinPE 组件。To change languages by using an answer file, use the Microsoft-Windows-International-Core-WinPE component. 可以在两个组件中指定语言设置:There are two components in which you can specify language settings:

  • Microsoft-Windows--WinPE-WinPEMicrosoft-Windows-International-Core-WinPE. windowsPE 配置阶段中应用语言设置。Language settings are applied during the windowsPE configuration pass.
  • Microsoft-Windows-国际核心Microsoft-Windows-International-Core. 语言设置在 specializeoobeSystem 配置阶段中应用。Language settings are applied during the specialize or oobeSystem configuration pass.

由于某些语言需要重新启动,因此,我们建议你在 windowsPE 配置阶段配置你的语言设置,因为计算机将始终重启。Because some languages require a restart, we recommend that you configure your language settings during the windowsPE configuration pass because the computer will always restart. 如果在 specializeoobeSystem 配置阶段过程中处理语言设置,则计算机可能需要额外重新启动。If you process language settings during the specialize or oobeSystem configuration pass, the computer might require an additional restart.

结合使用 Sysprep/通用化命令和 LocalAccounts 来更改帐户信息Use the Sysprep/generalize Command with LocalAccounts to Change Account Information

可以将 Sysprep 命令与 通用化 选项和 LocalAccounts 设置结合使用来更改现有用户帐户的帐户信息。You can use the Sysprep command with the generalize option and the LocalAccounts settings to change account information about an existing user account.

如果在 specialize 配置阶段中指定以下示例中的设置,则将更改 NEWVALUE 的所有值。If you specify the settings in the following example in the specialize configuration pass, all the values of NEWVALUE will be changed. 但是, 我的帐户 将保留其安全组成员身份。However, MyAccount will retain its security group memberships. 我的帐户 被视为具有不同显示名称、说明和密码值的相同帐户。MyAccount is considered to be the same account with a different display name, description, and password value.

<LocalAccount>
   <Name>MyAccount</Name>
   <DisplayName>NEWVALUE</DisplayName>
   <Description>NEWVALUE</Description>
   <Password>
      <PlainText>false</PlainText>
      <Value>NEWVALUEBASE64</Value>
   </Password>
</LocalAccount>

Windows 系统映像管理器 (Windows SIM) 技术参考Windows System Image Manager (Windows SIM) Technical Reference

Sysprep 概述Sysprep Overview

Windows 安装程序技术参考Windows Setup Technical Reference

部署映像服务和管理 (DISM)Deployment Image Servicing and Management (DISM)