Del via


Use Answer Files with Sysprep

You can use an answer file together with the System Preparation (Sysprep) tool to configure unattended Windows Setup settings. This topic describes some considerations and processes for using answer files together with Sysprep. For more information about Windows components and settings that you can add to an answer file, see the Unattended Windows Setup Reference.

Running Sysprep an Unlimited Number of Times

If you specify a product key, Windows is automatically activated, and you can run the Sysprep command an unlimited number of times. To automatically activate Windows by supplying a product key, specify a valid product key in the Microsoft-Windows-Shell-Setup\ProductKey unattend setting during the specialize configuration pass. If you don't automatically activate Windows by providing a product key, Windows prompts the end user for a product key.

Applying Settings in the generalize, auditSystem, and auditUser Configuration Passes

Not all configuration passes run during Windows Setup. The generalize, auditSystem, and auditUser configuration passes are available only when you run Sysprep.

The following settings are only processed if you run Sysprep:

  • Settings in the auditSystem and auditUser configuration passes are processed when you boot into Audit mode after running the Sysprep /audit command.

  • Settings in the generalize configuration pass are processed when you run the Sysprep /generalize command. The generalize configuration pass removes the system-specific settings so that you can deploy the same image on multiple computers.

For more information, see How Configuration Passes Work.

Caching Answer Files to the Computer

If you use an answer file to install Windows, that answer file is cached to the system. When later configuration passes run, the computer applies settings in that answer file to the system. Because this answer file is cached, when you run the Sysprep command, the system applies settings in the cached answer file. If you want to use the settings from a different answer file, you can specify a separate Unattend.xml file by using the Sysprep /unattend:<file_name> option.

Persisting Plug and Play Device Drivers During the generalize Configuration Pass

You can persist device drivers when you run the Sysprep /generalize command by using an answer file that has the Microsoft-Windows-PnPSysprep PersistAllDeviceInstalls component set to true. During the specialize configuration pass, Plug and Play scans the computer for devices, and then installs device drivers for the detected devices. By default, the computer uninstalls these device drivers from the system when you generalize the system.

Displaying RunSynchronous Actions in an Answer File

In Audit mode, you can view the status for Microsoft-Windows-Deployment RunSynchronous commands that run during the auditUser configuration pass. The AuditUI window displays the status for commands and provides:

  • Visual progress to indicate that an installation is continuing and not suspended.
  • Visual indication of when and where failures occur. This provides a quick diagnosis if the command doesn't create log files.

If the answer file contains Microsoft-Windows-Deployment RunSynchronous commands in the auditUser configuration pass, a list of the commands appears in the AuditUI window. The commands appear in the order that the Microsoft-Windows-Deployment-RunSynchronous-RunSynchronousCommand Order setting specifies. Each list item in the user interface is the string from one of these:

  • Microsoft-Windows-Deployment-RunSynchronous-RunSynchronousCommand Description (if present)
  • Microsoft-Windows-Deployment-RunSynchronous-RunSynchronousCommand Path

Sysprep processes all RunSynchronous commands in order. If the command succeeds, its related list item receives a green check-mark annotation. If the command fails, its related list item receives a red X annotation. If the command requests a reboot, the AuditUI window appears after the boot, but only unprocessed list items appear. Previously processed items no longer appear in the AuditUI window. If the list of items in the AuditUI window exceeds the height of the display, the list is truncated to the display and doesn't scroll. As a result, you may not be able to see some items.

Windows Setup interprets the return codes as status values in the AuditUI window. A zero value indicates a success. A nonzero value indicates a failure. The return value of the command might affect the behavior of Windows Setup, depending on the value of the Microsoft-Windows-Deployment-RunSynchronous-RunSynchronousCommand WillReboot setting.

Rebooting

  • If the WillReboot command is set to Always:

    • If the command returns 0, its related list item receives a green check-mark annotation. A reboot immediately occurs.
    • If the command returns a nonzero number, its related list item receives a red X annotation. A reboot immediately occurs. A nonzero return value isn't treated as a fatal error when WillReboot is set to either Always or Never.
  • If the WillReboot command is set to Never:

    • If the command returns 0, its related list item receives a green check-mark annotation.
    • If the command returns a nonzero number, its related list item receives a red X annotation. A nonzero return value isn't treated as a fatal error when WillReboot is set to either Always or Never.
  • If the WillReboot command is set to OnRequest:

    • If the command returns 0, its related list item receives a green check-mark annotation.
    • If the command returns 1, its related list item receives a green check-mark annotation. A reboot immediately occurs.
    • If the command returns 2, its related list item temporarily receives a green check-mark annotation. A reboot immediately occurs. After the reboot, the related list item appears again in the AuditUI window without annotation because the command is still in process.
    • If the command returns other values, a fatal error occurs and a blocking dialog box appears. If the Errorhandler.cmd file is present, no dialog box appears. For more information about the Errorhandler.cmd file, see Add a Custom Script to Windows Setup.

Sysprep (System Preparation) Overview

Sysprep Command-Line Options

Sysprep Support for Server Roles

Sysprep Process Overview

Deployment Troubleshooting and Log Files