Windows 安装程序自动化概述Windows Setup Automation Overview

使用 Setupconfig.ini 安装 WindowsUse Setupconfig.ini to install Windows

什么是 setupconfig 文件?What is a setupconfig file?

Setupconfig 是一个配置文件,用于将一组标志或参数传递给 Windows setup.exe。Setupconfig is a configuration file that is used to pass a set of flags or parameters to Windows setup.exe. 使用此文件作为将参数传递到命令行上的 Windows 安装程序的替代方法。Use this file as an alternative to passing parameters to Windows setup on a command line. 此功能在 Windows 10 版本1511及更高版本中可用。This functionality is available in Windows 10, version 1511 and later.

IT 专业人员可以使用 setupconfig 文件将参数添加到 Windows 更新和 Windows Server Update Services 的 Windows 安装程序。IT pros can use the setupconfig file to add parameters to Windows Setup from Windows Update and Windows Server Update Services.

本主题介绍了可用于 Windows 10 Setup.exe 的不同参数。The different parameters that can be used with Windows 10 Setup.exe are described in this topic.

Setupconfig.ini 文件可以包含单个参数,也可以包含参数和值对。Setupconfig.ini files can contain single parameters, or parameters and value pairs. 不要包含 "/" 字符,对于参数和值对,请在两者之间包含 "="。Do not include “/” characters, and with parameter and value pairs, include “=” between the two.

例如,使用以下项创建 Setupconfig.ini。For example, you create a Setupconfig.ini with the following. 请注意,此标头 [SetupConfig] 是必需的。Note that the header [SetupConfig] is required.

[SetupConfig]
NoReboot
ShowOobe=None
Telemetry=Enable
InstallDrivers=<path of folder containing INF and SYS drivers>
ReflectDrivers=<path of folder containing INF and SYS files for the encryption drivers>

这等效于以下命令行:This is equivalent to the following command line:

Setup /NoReboot /ShowOobe None /Telemetry Enable

Windows 安装程序如何使用 Setupconfig.ini?How does Windows Setup use Setupconfig.ini?

使用 media/ISO 文件Using media/ISO file

如果从媒体或 ISO 文件运行 Windows 安装程序,则在运行 setup.exe 时,必须在命令行 ( "/ConfigFile" ) 上包含 setupconfig 文件的位置 <path>If you are running Windows setup from media or an ISO file, you must include the location to the setupconfig file on the command line (“/ConfigFile <path>”) when running setup.exe. 例如:For example:

Setup.exe /ConfigFile <path to Setupconfig.ini>

如果在命令行中包含参数,并在 setupconfig 文件中包含相同的参数,则 setupconfig 文件参数和值优先。If you include a parameter on the command line and the same parameter in the setupconfig file, the setupconfig file parameter and value has precedence.

使用 Windows 更新Using Windows Update

如果通过 Windows 更新传递更新,Windows 安装程序在默认位置搜索 setupconfig 文件。If the update is delivered through Windows Update, Windows Setup searches in a default location for a setupconfig file. 可以在以下位置包含 setupconfig 文件:You can include the setupconfig file here:

"% systemdrive% \Users\Default\AppData\Local\Microsoft\Windows\WSUS\SetupConfig.ini""%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\WSUS\SetupConfig.ini"

安装 Windows 时使用应答文件Use an answer file while installing Windows

可以使用应答文件自动执行 Windows 安装:You can automate Windows installation by using an answer file:

使用安装程序进行服务:使用包含 Windows 安装程序、Windows 映像文件和 unattend.xml 自定义文件的 USB 的新设备开始。

使用 USB 闪存驱动器Use a USB flash drive

  1. 使用示例答案文件或使用 Windows 系统映像管理器创建自己的 (Windows SIM) 。Use a sample answer file or create your own with Windows System Image Manager (Windows SIM).

  2. 将该文件另存为 USB 闪存驱动器根目录中的 Autounattend.xmlSave the file as Autounattend.xml on the root of a USB flash drive.

  3. 在新电脑上,放入 Windows 产品 DVD 和 USB 闪存驱动器,然后启动电脑。On a new PC, put in the Windows product DVD and the USB flash drive, and then boot the PC. 如果未选择其他答案文件,则 Windows 安装程序搜索此文件。When no other answer file is selected, Windows Setup searches for this file.

选择应答文件Select an answer file

  • 可以在安装过程中选择特定答案文件,方法是启动到 Windows 预安装环境,并使用具有 /unattend:filename选项的 setup.exe 命令。You can select a specific answer file during installation by booting to the Windows Preinstallation Environment, and using the setup.exe command with the /unattend:filename option. 有关详细信息,请参阅 WinPE:创建 USB 可启动驱动器For more information, see WinPE: Create USB Bootable drive.

有关示例应答文件和用于自动执行安装的设置的列表,请参阅 自动 Windows 安装程序For sample answer files and a list of settings used to automate installation, see Automate Windows Setup.

修改现有安装Modify an existing installation

由于在安装过程中需要重新启动,因此会将应答文件的副本缓存到 Windows 安装的% WINDIR% \ Panther 目录中。Because reboots are required during Setup, a copy of the answer file is cached to the %WINDIR%\Panther directory of the Windows installation. 您可以修改此文件以执行以下任一操作:You can modify this file to do any of the following:

  • 更新 "系统" 和 "控制面板" 设置,而不启动映像。Update system and control panel settings without booting the image.

  • 通过准备 PC 以启动到审核模式来更新映像 (参阅 Microsoft Windows 部署重新 \ 封装 \ 模式) 。Update an image by preparing the PC to boot to audit mode (see Microsoft-Windows-Deployment\Reseal\Mode).

  • 更新安装驱动程序或包的顺序。Update the order in which drivers or packages are installed. 具有依赖关系的 (包可能需要按特定顺序安装。 ) (Packages with dependencies may require installation in a certain order.)

替换脱机映像中的应答文件Replace the answer file in an offline image

  1. 在 Windows 系统映像管理器中创建自定义应答文件 (Windows SIM) 。Create a custom answer file in Windows System Image Manager (Windows SIM).

  2. 打开权限提升的命令提示符。Open an elevated command prompt.

  3. 装载 Windows 映像。Mount the Windows image.

    Dism /Mount-Image /ImageFile:"C:\images\CustomImage.wim" /Index:1 /MountDir:C:\mount
    
  4. 修改或替换已 \ \ 装载的映像中的文件: Windows Panther \unattend.xml。Modify or replace the file: \Windows\Panther\unattend.xml in the mounted image.

    Copy CustomAnswerFile.xml C:\mount\Windows\Panther\unattend.xml
    

    注意Note
    映像中的应答文件可能包含尚未处理的设置。The answer file in the image may contain settings that have not yet been processed. 如果希望处理这些设置,请编辑现有文件而不是替换。If you want these settings to get processed, edit the existing file rather than replacing it.

  5. 卸载映像。Unmount the image.

    Dism /Unmount-Image /MountDir:C:\mount /Commit
    
  6. 通过将映像部署到新 PC 来测试映像,而无需指定应答文件。Test the image by deploying it to a new PC, without specifying an answer file. 当 Windows 安装程序运行时,它将查找并使用此答案文件。When Windows Setup runs, it finds and uses this answer file.

模糊应答文件搜索顺序Implicit Answer File Search Order

Windows 安装程序在每个配置阶段的开头搜索应答文件,包括初始安装和应用和启动映像之后。Windows Setup searches for answer files at the beginning of each configuration pass, including the initial installation and after applying and booting an image. 如果找到了答案文件,并且该文件包含给定配置阶段的设置,则会处理这些设置。If an answer file is found, and it contains settings for the given configuration pass, it processes those settings.

Windows 安装程序根据搜索顺序标识并记录所有可用的答案文件。Windows Setup identifies and logs all available answer files, depending on the search order. 将使用具有最高优先级的答案文件。The answer file that has the highest precedence is used. 将会对应答文件进行验证,然后将其缓存到计算机中。The answer file is validated and then cached to the computer. 有效的应答文件将缓存到 $Windows。 ~ BT \ 源 \ Panther 目录, windowsPEofflineServicing 配置通过。Valid answer files are cached to the $Windows.~BT\Sources\Panther directory during the windowsPE and offlineServicing configuration passes. 将 Windows 安装解压到硬盘之后,应答文件缓存到% WINDIR% \ panther。After the Windows installation is extracted to the hard disk, the answer file is cached to %WINDIR%\panther.

下表显示了模糊应答文件搜索顺序。The following table shows the implicit answer file search order.

搜索顺序Search Order 位置Location 说明Description

11

注册表Registry

HKEY_LOCAL_MACHINE\System\Setup\UnattendFileHKEY_LOCAL_MACHINE\System\Setup\UnattendFile

在注册表中指定指向应答文件的指针。Specifies a pointer in the registry to an answer file. 应答文件并非必须名为 Unattend.xml。The answer file is not required to be named Unattend.xml.

22

%WINDIR%\Panther\Unattend%WINDIR%\Panther\Unattend

答案文件的名称必须是 Unattend.xml 或 Autounattend.xml。The name of the answer file must be either Unattend.xml or Autounattend.xml.

注意 Note

Windows 安装程序仅在下层安装上搜索此目录。Windows Setup searches this directory only on downlevel installations. 如果 Windows 安装程序从 Windows PE 启动,则不会搜索 %WINDIR%\Panther\Unattend 目录。If Windows Setup starts from Windows PE, the %WINDIR%\Panther\Unattend directory is not searched.

33

%WINDIR%\Panther%WINDIR%\Panther

Windows 安装程序将答案文件缓存到此位置,以便在后续安装阶段使用。Windows Setup caches answer files to this location for use in subsequent stages of installation. 例如,当计算机重新启动时,安装程序可以继续应用答案文件中的设置。For example, when a computer reboots, Setup can continue to apply the settings in an answer file. 如果使用 Windows 安装程序或 Sysprep 显式指定答案文件,则缓存到此目录的答案文件将被显式指定的答案文件覆盖。If you explicitly specify an answer file by using Windows Setup or Sysprep, the answer file cached to this directory is overwritten with the explicitly specified answer file.

重要说明 Important

不要使用、修改或覆盖此目录中的应答文件。Do not use, modify, or overwrite the answer file in this directory. 此目录中的应答文件会在安装过程中使用 Windows 安装程序进行批注。The answer file in this directory is annotated by Windows Setup during installation. 此应答文件无法在 Windows SIM 或任何其他 Windows 安装中重复使用。This answer file cannot be reused in Windows SIM or any other Windows installations.

44

按照驱动器号顺序排列的可移动读/写介质,位于驱动器根目录下。Removable read/write media in order of drive letter, at the root of the drive.

按照驱动器号顺序排列的可移动读/写介质,位于驱动器根目录下。Removable read/write media in order of drive letter, at the root of the drive.

答案文件的名称必须是 Autounattend.xml 的,答案文件必须位于驱动器的根目录下。The name of the answer file must be Autounattend.xml, and the answer file must be located at the root of the drive.

55

按照驱动器号顺序排列的可移动只读介质,位于驱动器根目录下。Removable read-only media in order of drive letter, at the root of the drive.

按照驱动器号顺序排列的可移动只读介质,位于驱动器根目录下。Removable read-only media in order of drive letter, at the root of the drive.

答案文件的名称必须 Autounattend.xml,且必须位于驱动器的根目录下。The name of the answer file must be Autounattend.xml, and must be located at the root of the drive.

66

windowsPEofflineServicing 配置阶段:windowsPE and offlineServicing configuration passes:

  • Windows 分发中的 \Sources 目录\Sources directory in a Windows distribution

所有其他阶段:All other passes:

  • %WINDIR%\System32\Sysprep%WINDIR%\System32\Sysprep

windowsPEofflineServicing 配置阶段中,必须 Autounattend.xml 应答文件的名称。In the windowsPE and offlineServicing configuration passes, the name of the answer file must be Autounattend.xml.

对于所有其他配置阶段,文件名必须为 Unattend.xml。For all other configuration passes, the file name must be Unattend.xml.

77

%SYSTEMDRIVE%%SYSTEMDRIVE%

应答文件名必须是 Unattend.xml 或 Autounattend.xmlThe answer file name must be Unattend.xml or Autounattend.xml

88

驱动器,其中 Windows 安装程序 ( # A0) 在驱动器的根目录下运行。Drive from where Windows Setup (setup.exe) is running, at the root of the drive.

答案文件的名称必须 Unattend.xml 或 Autounattend.xml,并且必须位于 Windows 安装程序文件夹路径的根目录下。The name of the answer file must be Unattend.xml or Autounattend.xml, and must be located at the root of the Windows Setup folder path.

应答文件中的敏感数据Sensitive Data in Answer Files

安装程序将在每个配置阶段结束时删除缓存应答文件中的敏感数据。Setup removes sensitive data in the cached answer file at the end of each configuration pass.

重要说明Important
由于在 Windows 安装过程中会将应答文件缓存到计算机中,因此在数次重新启动之间应答文件将保留在计算机中。Because answer files are cached to the computer during Windows Setup, your answer files will persist on the computer between reboots. 在将计算机交付给客户之前,必须在% WINDIR% panther 目录中删除缓存的应答文件 \ 。Before you deliver the computer to a customer, you must delete the cached answer file in the %WINDIR%\panther directory. 如果在答案文件中包含域密码、产品密钥或其他敏感数据,则可能存在潜在的安全问题。There might be potential security issues if you include domain passwords, product keys, or other sensitive data in your answer file. 但是,如果你要在最终用户启动计算机时运行的 oobeSystem 配置阶段中存在未处理的设置,请考虑删除已处理的答案文件部分。However, if you have unprocessed settings in the oobeSystem configuration pass that you intend to run when an end user starts the computer, consider deleting the sections of the answer file that have already been processed. 运行 sysprep/oobe 命令时,一个选项可能是使用单独的答案文件,该文件只包含 oobeSystem 配置阶段的设置。One option when you run the sysprep /oobe command might be to use a separate answer file that only contains settings in the oobeSystem configuration pass.

但是,如果将答案文件嵌入到高于缓存的应答文件的优先级位置,则在每个后续配置阶段的开头,如果嵌入的应答文件与隐式搜索条件相匹配,则可能会覆盖缓存的答案。However, if an answer file is embedded in a higher precedence location than the cached answer file, then the cached answer may be overwritten at the beginning of each subsequent configuration pass, if the embedded answer file matches the implicit search criteria. 例如,如果答案文件嵌入到% WINDIR% \ Panther \ 无人参与 \Unattend.xml,则嵌入的应答文件将在每个配置阶段的开头替换缓存的应答文件。For example, if an answer file is embedded at %WINDIR%\Panther\Unattend\Unattend.xml, the embedded answer file will replace the cached answer file at the beginning of each configuration pass. 例如,如果嵌入的应答文件同时指定 specializeoobeSystem 配置阶段,则会发现嵌入的应答文件用于 specialize 配置传递、缓存、处理和敏感数据。For example, if the embedded answer file specifies both the specialize and oobeSystem configuration passes, then the embedded answer file is discovered for the specialize configuration pass, cached, processed, and sensitive data is cleared. 在 oobeSystem 配置阶段中再次发现嵌入的应答文件,并重新缓存。The embedded answer file is discovered again during the oobeSystem configuration pass and cached again. 因此,将不再清除 specialize 配置阶段的敏感数据。As a result, the sensitive data for the specialize configuration pass is no longer cleared. 先前处理的配置阶段的敏感数据将不会再次被清除。Sensitive data for previously processed configuration passes will not be cleared again. 除非必须重写缓存的答案文件,否则请将答案文件嵌入到优先级较低的位置。Unless the cached answer file must be overridden, embed the answer files at a location that has a lower precedence.

重要说明Important
由于在 Windows 安装过程中会将应答文件缓存到计算机中,因此在数次重新启动之间应答文件将保留在计算机中。Because answer files are cached to the computer during Windows Setup, your answer files will persist on the computer between reboots. 在将计算机交付给客户之前,必须在% WINDIR% panther 目录中删除缓存的应答文件 \ 。Before you deliver the computer to a customer, you must delete the cached answer file in the %WINDIR%\panther directory. 如果在答案文件中包含域密码、产品密钥或其他敏感数据,则可能存在潜在的安全问题。There might be potential security issues if you include domain passwords, product keys, or other sensitive data in your answer file. 但是,如果你要在最终用户启动计算机时运行的 oobeSystem 配置阶段中存在未处理的设置,请考虑删除已处理的答案文件部分。However, if you have unprocessed settings in the oobeSystem configuration pass that you intend to run when an end user starts the computer, consider deleting the sections of the answer file that have already been processed. 运行 sysprep/oobe 命令时,一个选项可能是使用单独的答案文件,该文件只包含 oobeSystem 配置阶段的设置。One option when you run the sysprep /oobe command might be to use a separate answer file that only contains settings in the oobeSystem configuration pass.

可以将命令添加到 Setupcomplete.cmd 命令脚本,该脚本可删除计算机上所有缓存的或嵌入的应答文件。You can add a command to the Setupcomplete.cmd command script that deletes any cached or embedded answer files on the computer. 有关详细信息,请参阅 将自定义脚本添加到 Windows 安装程序For more information, see Add a Custom Script to Windows Setup.

Windows 安装程序为应答文件中的配置阶段添加注释Windows Setup Annotates Configuration Passes in an Answer File

处理完某个配置阶段后,Windows 安装程序将对缓存的应答文件添加注释,以表明该阶段已处理。After a configuration pass is processed, Windows Setup annotates the cached answer file to indicate that the pass has been processed. 如果配置阶段再次运行,并且在过渡期间尚未替换或更新缓存的应答文件,则不会再次处理答案文件设置。If the configuration pass is run again and the cached answer file has not been replaced or updated in the interim, the answer file settings are not processed again. 相反,Windows 安装程序将搜索优先级较低(优先级低于缓存的 Unattend.xml 文件)位置的模糊 Unattend.xml 文件。Instead, Windows Setup will search for implicit Unattend.xml files that are at a lower precedence location than the cached Unattend.xml file.

例如,你可以在 specialize配置阶段中使用包含 Microsoft Windows 部署/RunSynchronous 命令的答案文件来安装 Windows。For example, you can install Windows with an answer file that contains Microsoft-Windows-Deployment/RunSynchronous commands in the specialize configuration pass. 在安装过程中,将运行 specialize 配置阶段并执行 RunSynchronous 命令。During installation, the specialize configuration pass runs and the RunSynchronous commands execute. 安装完成后,运行 sysprep 命令和 /generalize 选项。After installation, run the sysprep command with the /generalize option. 如果没有答案文件的优先级高于缓存的应答文件,或者没有将答案文件显式传递给 Sysprep 工具,则安装程序将在下次启动计算机时运行 specialize 配置阶段。If there is no answer file in a higher precedence than the cached answer file or an answer file was not explicitly passed to the Sysprep tool, Setup runs the specialize configuration pass the next time that the computer boots. 由于缓存的应答文件包含一个批注,该批注已应用该配置阶段的设置,因此不执行 RunSynchronous 命令。Because the cached answer file contains an annotation that the settings for that configuration pass were already applied, the RunSynchronous commands do not execute.

隐式答案文件搜索示例Implicit Answer File Search Examples

以下示例帮助描述模糊应答文件搜索的行为。The following examples help describe the behavior of implicit answer file searches.

将自动发现名为 Autounattend.xml 的答案文件 Windows 安装程序Answer Files Named Autounattend.xml are Automatically Discovered by Windows Setup

  1. 创建一个名为 Autounattend.xml 的答案文件,该文件包含 windowsPE 配置阶段中的设置。Create an answer file that is named Autounattend.xml that includes settings in the windowsPE configuration pass.

  2. 将 Autounattend.xml 复制到可移动媒体设备。Copy Autounattend.xml to a removable media device.

  3. 如果要从 CD 或 DVD 启动,请配置计算机的 BIOS。Configure the BIOS of your computer to boot from CD or DVD.

  4. 启动 Windows 产品 DVD。Boot the Windows product DVD.

  5. 在 Windows 启动时插入可移动媒体设备。Insert the removable media device when Windows is booting. 此示例假设向可移动介质分配驱动器号 D: \ 。This example assumes that the removable media is assigned the drive letter D:\.

    Windows 安装程序将会启动并自动将 Autounattend.xml 识别为有效的应答文件。Windows Setup starts and automatically identifies Autounattend.xml as a valid answer file. 由于应答文件使用有效的文件名 ( # A0) ,位于 D) 的根目录 (的一个有效搜索路径中,并包括当前配置阶段的有效设置 (windowsPE) ,使用此答案文件。Because the answer file uses a valid file name (Autounattend.xml), is located in one of the valid search paths (the root of D), and includes valid settings for the current configuration pass (windowsPE), this answer file is used.

    会将应答文件缓存到计算机中。The answer file is cached to the computer. 如果在之后的阶段中未发现其他应答文件,则整个 Windows 安装程序过程中都将使用该缓存的文件。If there are no additional answer files discovered in later passes, the cached answer file is used throughout Windows Setup.

按优先顺序在预定义搜索路径中发现答案文件Answer Files are Discovered in Order of Precedence in Predefined Search Paths

  1. 使用前面方案中的步骤通过应答文件安装 Windows。Install Windows with an answer file by using the steps in the previous scenario. 用于安装 Windows 的应答文件缓存到% WINDIR% Panther 目录中的系统 \ 。The answer file that is used to install Windows is cached to the system in the %WINDIR%\Panther directory.

  2. 将 Unattend.xml 文件复制到% WINDIR% \ System32 \ Sysprep 目录。Copy an Unattend.xml file to the %WINDIR%\System32\Sysprep directory.

    此应答文件在 通用化 配置阶段中具有设置。This answer file has settings in the generalize configuration pass.

  3. 使用 /generalize 选项运行 sysprep 命令以创建引用映像。Run the sysprep command with the /generalize option to create a reference image.

    由于% WINDIR% \ System32 \ Sysprep 目录位于隐式搜索路径中,因此会找到复制到此目录的答案文件。Because the %WINDIR%\System32\Sysprep directory is in the implicit search paths, the answer file copied to this directory is found. 但是,用于安装 Windows 的答案文件仍会缓存在计算机上,并包含 通用化 配置阶段的设置。However, an answer file that was used to install Windows is still cached on the computer and contains settings for the generalize configuration pass. 此缓存的应答文件的优先级要高于复制到 Sysprep 目录中的文件的优先级。This cached answer file has a higher precedence than the one copied to the Sysprep directory. 会使用缓存的应答文件。The cached answer file is used.

    注意Note
    Sysprep 工具可以作为命令行工具或 GUI 工具运行。The Sysprep tool can be run as a command-line tool or as a GUI tool. 如果将 Sysprep 工具作为 GUI 工具运行,则可以选中 " 通用化 " 复选框。If you run the Sysprep tool as a GUI tool, you can select the Generalize check box.

To use the new answer file, you can copy it to a directory of a higher precedence than the cached answer file, or you can specify the answer file by using the **/unattend** option. For example:

```
sysprep /generalize /unattend:C:\MyAnswerFile.xml
```

答案文件必须包含有效的配置阶段Answer Files Must Include a Valid Configuration Pass

  1. 将 Unattend.xml 文件复制到可移动介质设备。Copy an Unattend.xml file to a removable media device.

    Unattend.xml 文件仅包含 auditSystemauditUser 配置阶段的设置。The Unattend.xml file has settings only for the auditSystem and auditUser configuration passes.

  2. 在已安装的 Windows 操作系统上,运行 sysprep/generalize/oobe 命令。On an installed Windows operating system, run the sysprep /generalize /oobe command.

    即使答案文件在某个隐式搜索路径中可用,Unattend.xml 文件也会被忽略,因为它不包含 通用化 配置阶段的有效 pass。Even though the answer file is available in one of the implicit search paths, the Unattend.xml file is ignored because it does not contain a valid pass for the generalize configuration pass.

其他资源Additional Resources

有关答案文件和配置阶段的详细信息,请参阅下列主题:See the following topics for more information about answer files and configuration passes:

相关主题Related topics

Windows 安装程序方案和最佳实践Windows Setup Scenarios and Best Practices

Windows 安装程序安装过程Windows Setup Installation Process

自动化 Windows 安装Automate Windows Setup

审核模式概述Audit Mode Overview

Windows Setup Configuration PassesWindows Setup Configuration Passes

Windows 安装程序支持的平台和跨平台部署Windows Setup Supported Platforms and Cross-Platform Deployments