Sysprep a Windows 7 Machine – Start to Finish V2

SPREAD THE WORD, TOGETHER WE HAVE CONQUERED SYSPREP :)

This is version 2 of a step by step guide on Sysprepping a Windows 7 machine from start to finish. I cannot take full credit on this because my first article had so many helpful comments and discussions that this is simply a combination of all the good advice written into a working guide. (I would especially like to thank George for his input on Cscript for auto activation and Nathan for input on Sysprep Audit Mode). This will guide you through the following:

- Audit Mode
- Building the unattend.xml file in WSIM
- copyprofile=true command to copy the default profile (no manual copy)
- Prompt for a computer name
- Enable Administrator account
- Administrator account logs in first time automatically
- Activate windows automatically with Cscript;
- Successfully copy over taskbar icons;
- Delete unattend.xml file automatically upon completion of re-image.

Here is a list of what you will need:

- Latest version of WAIK : KB3AIK_EN.iso Version 1.0
- Windows Vista or Windows 7 Machine to build the XML file on
- ISO or DVD of Windows 7 Installation (x32 or x64)
- WinPE Boot Environment : BrianLeeJackson WinPE 3.0 BootLoader

First we are going to walk through building the unattend.xml file (answer file) and then we will walk through the actual Windows 7 imaging process.

PART 1 – XML FILE CREATION

Step #1

If you have a Windows 7 installation DVD, insert it now. Or if you have an ISO of 7, go ahead and extract it to a folder on your desktop. (I recommend 7-zip).

Step #2

Launch Windows System Image Manager. Your start menu should look like the image below:

Windows 7 WAIK Version 1

Windows 7 WAIK Version 1

Step #3

Under the “Windows Image” header, right click and select new image.

Windows System Image Manager

Windows System Image Manager

Step #4

You will now want to browse to the .CLG file in your Windows 7 installation (I am using Windows 7 Enterprise x64 in my example). It is located in the sources folder. See Image below. You can select either the .clg file or the install.wim. Both will have the same result.

Selecting CLG File - WSIM

Selecting CLG File - WSIM

Step #5

Now we need to create a new answer file. Go to the file menu and select “Create New Answer File.” Right after creating one, go ahead and simply go to file menu and select “Save Answer File.” This will give your XML file a name and save location. I chose to name mine unattend.xml. Now you see we have two category folders, Components and Packages. Under the Components folder you see that we have 7 options:

-1 windowsPE
-2 offlineServicing
-3 generalize
-4 specialize
-5 auditSystem
-6 auditUser
-7 oobeSystem

Step #6

These are very important as these are the steps in which the unattend.xml file is sequenced.
The next part is a little confusing. You are going to add components, from under the “Windows Image” section on the bottom left hand side to the passes on your Answer File. To add a component, you can right click on them and select “add to # pass”. There are many different options you can add, but they have to be done in a certain order and pass otherwise your sysprep might fail. I am simply going to use the one I created as the example.

Answer File - Unattend.xml

Answer File - Unattend.xml

Here is more information about adding options under the passes:

1 windowsPE

Nothing required in my example.

2 offlineServicing

Nothing required in my example.

3 generalize

amd64_Microsoft-Windows-Security-SPP_6.1.7600.16385_neutral

Set 1 for SkipRearm to allow up to 8 rearms

4 specialize

amd64_Microsoft-Windows-Deployment_6.1.7600.16385_neutral

      1. Order: 1
        path: net user administrator /active:yes
        WillReboot: Never
    1. RunSynchronousCommand[Order="1"]

  1. RunSynchronous

amd64_Microsoft-Windows-Security-SPP-UX_6.1.7600.16385_neutral

SkipAutoActivation: true

amd64_Microsoft-Windows-Shell-Setup_6.1.7600.16385_neutral

Computer Name: Leave blank (we will deal with this at the end)
CopyProfile: true
Registered Organization: Microsoft (you must leave this in this section)
Registered Owner: AutoBVT (you must leave this in this section)
ShowWindowsLive: false
TimeZone: Pacific Standard Time

You can delete other sub-header components if you don’t need them.

5 auditSystem

Nothing required in my example.

6 auditUser

Nothing required in my example.

7 oobeSystem

amd64_Microsoft-Windows-International-Core_6.1.7600.16385_neutral

InputLocale: en-us
SystemLocale: en-us
UILanguage: en-us
UserLocale: en-us

amd64_Microsoft-Windows-Shell-Setup_6.1.7600.16385_neutral

RegisteredOrganization: Your Company Name
RegisteredOwner: Your Name

  • AutoLogon
      1. Password: Administrator Password
    1. Enabled: true
      LogonCount: 5
      Username: administrator

  • FirstLogonCommands
      1. CommandLine: cscript //b c:\windows\system32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX (windows 7 license key)
        Order 1
        RequiresUserInput: false
        CommandLine: cscript //b c:\windows\system32\slmgr.vbs /ato
        Order 2
        RequiresUserInput: false
    1. SynchronousCommand[Order="1"]

      SynchronousCommand[Order="2"]

  • OOBE
    1. HideEULAPage: true
      NetworkLocation: Home
      ProtectYourPC: 1
  • UserAccounts
          1. Password: Administrator Password
        1. Action: AddListItem
          Description: Local Administrator
          DisplayName: Administrator
          Group: Administrators
          Name: Administrator

      1. LocalAccount[Name="Administrator"]

    1. AdministratorPassword: Administrator Password
      LocalAccounts

    If you have questions, look at my image above to see full layout of components, it should help.

    Step #7

    K, now go ahead and save your answer file as unattend.xml.

    Step #8

    If you want the sysprep to prompt for a computer name you need to remove a line from your XML file. Open up your XML file you saved with notepad and remove the following line:

    Unattend.xml Computer Name

    Unattend.xml Computer Name

    PART 2 – IMAGING PROCESS / RUNNING SYSPREP

    Step #9

    Install Windows 7 (Enterprise) from CD or USB flash drive, when you arrive at the welcome screen and it asks you to create a username, hit ctrl+shift+f3.
    This will reboot your machine and put your windows build in ‘audit’ mode.

    Step #10

    On reboot, you’ll automatically be logged in under the built-in Administrator account. A sysprep GUI box will appear, but you can close it and NOW begin to customize your profile.

    Step #11

    Install any software/drivers, make any profile customizations, etc.
    If you need to reboot, the computer will boot you back into the Administrator account. You will be stuck in this audit mode until you run sysprep with the /oobe parameter. After doing so, sysprep will delete/clean up the Administrator account, but if you have copyprofile=true in your unattended answer file, it will copy the customized Admin account to the default profile before deleting it.

    Step #12

    On the PC you are going to be running sysprep on, you need to create a folder called scripts in this directory: %WINDIR%\Setup\. Now you are going to create a CMD file within the %WINDIR%\Setup\Scripts directory. Right click and make a new text file called SetupComplete.txt. Remove the .txt extension and replace that with .cmd. You now have a SetupComplete.cmd file which windows will read the first time it boots up from the sysprep. We need to place a script inside the CMD file. Edit the cmd file with notepad and insert this line: del /Q /F c:\windows\system32\sysprep\unattend.xml. This script will delete your unattend.xml file after it has been used. The unattend.xml file is also copied to the C:\Windows\Panther directory, so you will want to add a second line to the CMD file, del /Q /F c:\windows\panther\unattend.xml. If you have passwords or cd keys stored in that xml file you don’t have to worry about it being left on the computer.

    UPDATE AS OF JUNE 16TH: Read my Taskbar Icons Tutorial before continuing.

    Step #13

    Once you have everything configured correctly, Copy or move your unattend.xml file to : C:\windows\system32\sysprep. Now to run sysprep, navigate to that sysprep folder, hold SHIFT and right click and select “Open New Command Windows Here”. Next, input the following commands:

    sysprep /generalize /oobe /shutdown /unattend:unattend.xml

    Step #14

    Turn the computer back on and boot to WinPE 3.0 environment (USB stick or CD/DVD). You can use my BrianLeeJackson WinPE3.0 BootLoader to boot up from USB or CD and capture your image. Capture image and save image to network location.
    A Dell 960 or GX755 is a good standard for capturing when you want a generic image for use with multiple systems. Might require injecting additional drivers for 3rd party brands, HP, etc. Most should work though right out of the box.

    Step #15

    On reboot, Windows will run out of the box, as the /oobe is intended. As long as you put your cd key into the unattend.xml file, windows will be activated automatically in the background, you will be automatically logged into the administrator account, and the unattend.xml file is deleted. You are now ready to use the computer or join it to the domain. Enjoy!

    Share and Enjoy:
    • Twitter
    • Facebook
    • Digg
    • del.icio.us
    • Technorati
    • StumbleUpon
    • Google Bookmarks

    Tags: , , , , ,

    328 Responses to “Sysprep a Windows 7 Machine – Start to Finish V2”

    1. tam says:

      @LouisG sounds like it worked, but CopyProfile doesn’t copy everything. A good test is to change the theme in the source account.

      Using audit mode is a MYTH. As long as only one account is in the ProfileList registry entry, you can be sure that account will be used for CopyProfile.

    2. Garry says:

      Great work, thanks for this guide and also thanks to Erik Sundin for the extra scripts to join domain and clean up the files. I now have a working sysprep that only asks for a computer name. Perfect for our company.

      Regards,

      Garry

    3. MarkF says:

      I followed the instructions for creating a base clean image. I have the image at the point of kicking off sysprep. I made an image using gimagex using the BLJ 3.0 bootable USB key. It seemed to work great. I restored the image to another same type computer to make sure I could reuse the image, and noticed it loaded ok. I did not clean off the old hard disk on a target computer. It kept all of the extra junk that was on the desktop on the target computer. Well, I decided to run the diskpart batch file that went through the formatting process. I loaded the WIM file on the target machine (recently formated disk) and after the image is loaded, the files are there but I get bootimg is missing.

    4. Rafi says:

      If I wanted it to prompt for the Windows License Key, would I simply omit the scripts under “FirstLogonCommands?”

      Thanks in advance.

    5. Julian says:

      Rafi if you omit the script windows wil not prompt during install, only later.

      Thx Brian, your tutorial is great! I have a working image now, only without copyprofile, it seems it does not work with w7 enterprise, even when fully updated. But the old trick of creating a user and copying it’s files, renaming users/default to something else and renaming the copied user to default works.

    6. [...] do is completely remove the line below from the specialize pass in your unattend.xml file (as shown here). [...]

    7. Mike Larios says:

      This is really indepth, I will apply this to the images and see how it turns out if it works I will repost back with my resulting success…

    8. DebS says:

      I have been able to create an image which looked perfect. Once my test clients began to use applications in the image we discovered that the client does not ‘own’ the applications. The clients cannot, for example, put information into a pre-existing pdf form. Acrobat Reader crashes. What I’ve found is that the client’s profile does not have all the privs necessary to perform basic application functions. The administrator profile (copied to default user) still owns all the files and apps.
      Therefore it looks to me as though during the copy profile function, someone at Microsoft forgot to change ownership to ‘Everyone’, like we were able to do during copy profile in XP. Frustrating. I’m having to start from scratch as I’ve uninstalled and reinstalled and nothing changes the problem.
      Has anybody seen this? Got a fix?

    9. Marc says:

      I followed your steps but I had to enter the product key on the first reboot. Do you know what may have caused this?

    10. Jack H says:

      Brian, We’re using a MAK license here and can’t seem to get it to auto activate, any thoughts? I mean, are you using a MAK license? thanks

    11. Rob Demeuse says:

      This is great stuff, but I can’t get my answer file to work. Can you just post the basic answer file for download that you describe in the steps above? It would be nice to have the 32 and 64-bit. I am only looking to do what you have described above. It would be a big help. Or if you could post the content of the answer file less the activation code.

      Thanks a ton!

    12. Patrick says:

      Hello! I’m looking for a good sysprep. This one is rather complicated. Maybe using MDT 2010 makes it easier?

      Things I want to have is:
      In the domain i want to.
      User I input will be in group Administrators on this computer (not domain).
      My documents redirected to homefolder on serverlocation.

      Is these things possible?

    13. Amy says:

      I have noticed that a few settings are not copied when sysprep copy’s the profile to the default user profile. For example: Each time a user logs in to the computer and creates a profile they have to answer the questions of Internet Explorer 8, Windows Media Player, and when they click on Office 2010 applications they have to go through the activatation online. All of these things I do when I create the image, but it doesn’t keep them. We have labs on campus that the students will be logging into with their user name/password. These computers have deepfreeze installed and the students will have to answers these questions over and over again. Does anyone know of a solution for this?

    14. Dean says:

      Has anyone got the pc to join domain correctly after the computer name has been entered?

    15. tam says:

      Taskbar pins:

      copy this registry key:
      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband

      put shortcut .lnk files here:
      %userprofile%\appdata\roaming\microsoft\internet explorer\quick launch\user pinned\taskbar\

    16. Kyle says:

      What is the best course of action for making sure display drivers I install in audit mode are carried over after the sysprep process?

      I seem to be “losing” them after I run sysprep and lose Windows Aero with a very small screen resolution.

    17. Amy says:

      Does anyone have a script to make the quicklunch toolbar stay after the computer is imaged and comes out of sysprep?

    18. Kyle says:

      Ignore my last comment, I figured out what I needed in sysprep:

      true
      true

      Amy I think brian’s other article will help you out: http://blog.brianleejackson.com/copy-taskbar-icons-windows-7-sysprep

      Anyway, next question…

      I having one of my images I rebuilt from scratching using the same sysprep.xml file throwing an error on [specialize] at [Microsoft-Windows-Shell-Setup]. I only have the following under that context:

      *
      true
      false
      Central Standard Time

      Could it be having problems copying my profile? If so, what could most likely be causing the hangup?

    19. Kyle says:

      Oops, didn’t know xml tags got stripped. I meant to post:

      ComputerName * ComputerName
      CopyProfile true CopyProfile
      ShowWindowsLive false ShowWindowsLive
      TimeZone Central Standard Time TimeZone

    20. peled says:

      Hi kyle…
      what you find about the AERO probleme you had?
      What fixed it in the SYSPREP xml?
      i have the same problem….

    21. Vince says:

      Great post, this has been by far the most helpful information we have found for creating our unattended file. However, we have run into an activation-related issue.
      Now that the image was built over 30 days ago, we are being prompted with an “evaluation period has expired” error. This is occuring before any of the slmgr commands even run.

      Has anyone else seen this? Any ideas?

    22. Zaccy D says:

      This has to be one of the best guide’s I’ve found for Windows 7 Sysprep, Great Work !!!!!

      I do have a few issue though;

      I have built a Windows 7 Enterprise installation with all my applications and drivers installed ready to be deployed to our staff. I have created an unattended.xml file through the WAIK tools and defined all of my preferences and fully automated the installation however, when I seal the installation by running sysprep.exe /unattend:unattend.xml, the PC re-seals and restarts and fully automates the install but when I log in, the display driver has been uninstalled and has defaulted to the windows default one :S, Is there anyway I can stop this from happening and keeping the driver I installed before the sysprep?

      Also I would like the PC to recognize the LAN network it finds an address from first to be a “Work” network by default, What is the procedure to do this?

      Thanks in advance and keep up the good work
      Zaccy D

    23. Stewart says:

      Hi

      Gary can you expand on the quote below

      Great work, thanks for this guide and also thanks to Erik Sundin for the extra scripts to join domain and clean up the files. I now have a working sysprep that only asks for a computer name. Perfect for our company.

      I cant get this to work at all.
      In my Unattend.xml i have cscript //b c:\windows\system32\sysprep\domain-join.vbs
      I have copied the domian-join.vbs to c:\windows\system32\sysprep but the computer never joins the domain

      Cheers

      Stewart

    24. Kenny says:

      I had a similar problem and after looking thru the log file I was able to figure out what was causing the error. The log file I used was located here:

      %Windir%\Panther\UnattendGC\Setupact.log

    25. Nas says:

      This page had been a huge help to me and my company. I just have a couple of issues that I can’t resolve.
      1. It is not prompting me for a computer name or a registered owners name when doing this.
      2. How can I auto activate Windows during the setup?

      Here is my xml file…

      Please Please help.

      -
      -
      1

      -
      -
      false
      Central Standard Time
      false
      XXXXXXXXXXXXXXXXXXXXXXXXXXX

      -
      -
      -
      oww
      xxxxxxxxxx
      xxxxxxxxxx

      xxx.xxx.xxx
      false

      -
      false

      -
      -
      en-us
      en-us
      en-us
      en-us

      -
      -
      -
      SwBlAG4AcwBpAG4AZwB0ADAAbgBQAGEAcwBzAHcAbwByAGQA
      false

      localsysop
      1
      true

      -
      true
      true
      Work
      3
      true

      XXXXXXXXXX

    26. Nas says:

      oops… sorry.. here is my xml file

      - settings pass=”generalize”
      - component name=”Microsoft-Windows-Security-SPP” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      SkipRearm1/SkipRearm
      /component
      /settings
      - settings pass=”specialize”
      - component name=”Microsoft-Windows-Shell-Setup” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      CopyProfilefalse/CopyProfile
      TimeZoneCentral Standard Time/TimeZone
      ShowWindowsLivefalse/ShowWindowsLive
      ProductKeyXXXXXXXXXXXXXXXXXXX/ProductKey
      /component
      - component name=”Microsoft-Windows-UnattendedJoin” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      - Identification
      - Credentials
      Domainxxx/Domain
      PasswordXXXXXXXXX/Password
      UsernameXxxxxxxxx/Username
      /Credentials
      JoinDomainxxx.xxxx.xxx/JoinDomain
      DebugJoinfalse/DebugJoin
      /Identification
      /component
      - component name=”Microsoft-Windows-Security-SPP-UX” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      SkipAutoActivationfalse/SkipAutoActivation
      /component
      /settings
      - settings pass=”oobeSystem”
      - component name=”Microsoft-Windows-International-Core” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      InputLocaleen-us/InputLocale
      SystemLocaleen-us/SystemLocale
      UILanguageen-us/UILanguage
      UserLocaleen-us/UserLocale
      /component
      - component name=”Microsoft-Windows-Shell-Setup” processorArchitecture=”x86″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
      - AutoLogon
      - Password
      ValueSwBlAG4AcwBpAG4AZwB0ADAAbgBQAGEAcwBzAHcAbwByAGQA/Value
      PlainTextfalse/PlainText
      /Password
      Username xxxxxxx/Username
      LogonCount1/LogonCount
      Enabledtrue/Enabled
      /AutoLogon
      - OOBE
      HideEULAPagetrue/HideEULAPage
      HideWirelessSetupInOOBEtrue/HideWirelessSetupInOOBE
      NetworkLocationWork/NetworkLocation
      ProtectYourPC3/ProtectYourPC
      SkipMachineOOBEtrue/SkipMachineOOBE
      /OOBE
      RegisteredOrganizationxxxxxx xxxxxxx/RegisteredOrganization
      RegisteredOwner /
      /component
      /settings

    27. Christian says:

      I’m having trouble with the vbscript from Erik Sundin to join the computer to the domain. Just copied the script to notepad and saved as domain-join.vbs

      Set objShell = CreateObject “Wscript.Shell”
      objShell.Run(“powershell.exe -executionpolicy remotesigned -file c:\windows\system32\sysprep\domain-join.ps1″)

      When executing it, I get this:

      Line 1
      Char: 29
      Error: Invalid Character
      Code: 800A0408

      What gives, any ideas?

    Leave a Reply