Lab 7: Change settings, enter product keys, and run scripts with an answer file (unattend.xml)

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.

To learn about Windows customizations, see the most recent OEM Policy Document (OPD).

As an example, we'll add a setting that shows you how to automatically boot to a maintenance mode called audit mode. This mode allows you to perform additional tests, and capture changes. We'll use audit mode in the next few labs.

diagram of creating a new answer file

Windows settings overview

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. 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.

We'll show you more ways to add settings later in Lab 10: Add desktop applications and settings with siloed provisioning packages (SPPs).

Answer file settings

You can specify which configuration pass to add new settings:

  • 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: Most settings should be added here. These settings are triggered both at the beginning of audit mode and at the beginning of OOBE. 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: Runs as soon as you start audit mode.

    This is a great time to run a system test script - we'll add Microsoft-Windows-Deployment\RunAsynchronousCommand as our example. To learn more, see Add a Custom Script to Windows Setup.

  • 7 oobeSystem: Use sparingly. Most of these settings run after the user completes 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.

    If your script relies on knowing which language the user selects during OOBE, you’d add it to the oobeSystem pass.

  • To learn more, see Windows Setup Configuration Passes.

Note These settings could be lost if the user resets their PC with the built-in recovery tools. 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

Step 1: Create a catalog file

  1. Start Windows System Image Manager.

  2. Click File > Select Windows Image.

  3. In Select a Windows Image, browse to and select the image file (D:\install.wim). Next, select an edition of Windows, for example, Windows 10 Pro, and click OK. Click Yes to create the catalog file. 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.

    The catalog file appears in the Windows Image pane. Windows SIM lists the configurable components and packages in that image.

    Troubleshooting: If Windows SIM does not create the catalog file, try the following steps:

    • To create a catalog file for either 32-bit or ARM-based devices, use a 32-bit device.

    • 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.

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.

Step 3: Add new answer file settings

  1. Add OEM info:

    In the Windows Image pane, expand Components, right-click amd64_Microsoft-Windows-Shell-Setup_(version), and then select Add Setting to Pass 4 specialize.

    In the Answer File pane, select Components\4 specialize\amd64_Microsoft-Windows-Shell-Setup_neutral\OEMInformation.

    In the OEMInformation Properties pane, in the Settings section, select:

    • Manufacturer=Fabrikam
    • Model=Notebook Model 1
    • Logo=C:\Fabrikam\Fabrikam.bmp

    Create 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.

    We'll copy the logo into the Windows image in a few steps.

  2. Set the device to automatically boot to audit mode:

    In the Windows Image pane, expand Components, right-click amd64_Microsoft-Windows-Deployment_(version), and then select Add Setting to Pass 7 oobeSystem.

    In the Answer File pane, select Components\7 oobeSystem\amd64_Microsoft-Windows-Deployment_neutral\Reseal.

    In the Reseal Properties pane, in the Settings section, select Mode=Audit.

  3. Prepare a script to run after Audit mode begins.

    In the Windows Image pane, right-click amd64_ Microsoft-Windows-Deployment_(version) and then click Add Setting to Pass 6 auditUser.

    In the Answer File pane, expand Components\6 auditUser\amd64_Microsoft-Windows-Deployment_neutral\RunAsynchronous. Right-click RunAsynchronousCommand Properties and click Insert New 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 (Determines the order that commands are run, starting with 1.)

  4. Add a registry key. In this example, we add keys for the OEM Windows Store program. Use the same process as adding a script, using CMD /c REG ADD.

    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. By adding a SCM, you can target Customer Systems at a more granular level. 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.

    Add RunAsynchronousCommands for each registry key to add. (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

More common Windows settings:

  • Activate Windows by adding a product key: Microsoft-Windows-Shell-Setup\ProductKey. Please refer to the Kit Guide Win 10 Default Manufacturing Key OEM PDF to find default product keys for OA3.0 and Non-OA3.0 keys:

    OPK X21-08790 Win Home 10 1607 32 64 English OPK\Print Content\X20-09791 Kit Guide Win 10 Default Manufacturing Key OEM\X2009791GDE.pdf.

  • Speed up first boot by maintaining driver configurations when capturing an image: Microsoft-Windows-PnpSysprep/DoNotCleanUpNonPresentDevices, Microsoft-Windows-PnpSysprep/PersistAllDeviceInstalls.

  • Set the Internet Explorer default search engine: Create a RunAsynchronous command as shown above to add a registry key:

    Path = `CMD /c REG.exe add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\InternetSettings\Configuration m /v PartnerSearchCode /t REG_DWORD /d "{searchTerms}" /f`   
    Description = Changes the Internet Explorer default browser to Fabrikam Search
    Order = 3
    RequiredUserInput = false
  • Set the Internet Explorer search scopes: See Scope


    <component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="" xmlns:xsi="">
      <Scope wcm:action="add">             
  • Save drive space by reducing or turning off the hiberfile. The hiberfile helps speed up the time after the system powers up or recovers from low-power states. Create a RunAsynchronous command as shown below. To learn more, see Compact OS, single-instancing, and image optimization: RAM, Pagefile.sys, and Hiberfil.sys

    Path = `powercfg /h /type reduced`   
    Description = Saves drive space by reducing hiberfile by 30%.
    Order = 4
    RequiredUserInput = false


    Path = `powercfg /h /off`   
    Description = Turns off the hiberfile.
    Order = 4
    RequiredUserInput = false

Step 4: Save the answer file

  • Save the answer file, for example: D:\AnswerFiles\BootToAudit-x64.xml.

    Note Windows SIM will not allow you to save the answer file into the mounted image folders.

Step 5: Create a script

  • Copy 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

Mount the image

Step 6: Mount the images

Use the steps from Lab 3: Add device drivers (.inf-style) to mount the image. The short version:

  1. Open the command line as an administrator (Start > type deployment > right-click Deployment and Imaging Tools Environment > Run as administrator.)

  2. Make a backup of the file (copy "D:\Images\Win10_x64\sources\install.wim" D:\Images\install-backup.wim)

  3. Mount the image (md C:\mount\windows, then Dism /Mount-Image /ImageFile:"D:\Images\install.wim" /Index:1 /MountDir:"C:\mount\windows" /Optimize)

Add the answer file

Step 7: Add the answer file

  1. Copy the answer file into the image into the \Windows\Panther folder, and name it unattend.xml. Create the folder if it doesn’t exist. 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

    Unmount the images

Step 8: Unmount the images

  1. Close all applications that might access files from the image.

  2. Commit the changes and unmount the Windows image:

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

    where C is the drive letter of the drive that contains the mounted image.

    This process may take several minutes.

Try it out

Step 9: Apply the image to a new PC Use the steps from Lab 2: Deploy Windows using a script to copy the image to the storage USB drive, apply the Windows image and the recovery image, and boot it up. The short version:

  1. Copy the image file to the storage drive.
  2. Boot the reference device to Windows PE using the Windows PE USB key.
  3. Find the drive letter of the storage drive (diskpart, list volume, exit).
  4. Apply the image: D:\Deployment\ApplyImage.bat D:\Images\install.wim.
  5. Disconnect the drives, then reboot (exit).

Step 10: Verify settings and scripts

If your audit mode setting worked, the PC should boot to audit mode automatically. When audit mode starts, your script should start automatically.

  1. In File Explorer, check to see if the file: C:\Fabrikam\DxDiag-TestLogFiles.txt exists. If so, the SampleCommand.cmd sample script ran correctly.

Leave the PC booted into audit mode to continue to the following lab: