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).
Note – I highly recommend creating a boot or rescue disk before starting any windows 7 technical projects. There are many tools in the market and I use Spotmau BootSuite rescue software and boot disk utility because of it’s versatile features and top notch performance.
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
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).
Launch Windows System Image Manager. Your start menu should look like the image below:
Under the “Windows Image” header, right click and select new image.
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.
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:
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.
Here is more information about adding options under the passes:
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
If you have questions, look at my image above to see full layout of components, it should help.
K, now go ahead and save your answer file as unattend.xml.
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:
PART 2 – IMAGING PROCESS / RUNNING SYSPREP
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.
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.
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.
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.
Once you have everything configured correctly, Copy or move your unattend.xml file to : C:\windows\system32\sysprep.
Now to run sysprep you need to launch Command Prompt as an administrator. To do this press start, and type into the search CMD then right click on CMD and select run as Administrator. Next navigate to the sysprep folder by typing: cd sysprep and pressing enter.
Turn the computer back on and boot to WinPE 3.0 environment (USB stick or CD/DVD). You can use our TheITBros WinPE3.1 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.
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!
Thanks T800 for the tip: “Apparently I had to stop ‘Windows Media Player Network Sharing’ service before I could run /oobe /generalize, otherwise it gave me a fatal error.”
Dan Wright also mentioned that you need to set the network location to “Public” and/or delete some files and registry keys. See this article: http://technet.microsoft.com/en-us/library/ee676648(v=ws.10).aspx
To enable Aero your computer needs to calculate it’s performance score. Do you want to do that on each and every machine? No. So, if all machines have the same hardware, run this before syspreping your master-image :
This will calculate the performance index and put it on your machine in xml-format. If the OOBE wizard finds this xml file, and the hardware hasn’t changed, it uses the pre-populate values and Aero works out of the box.
From user comment:
After many hours of battling, I also found that a registry entry must be added for sysprep to look in the C:\Drivers location. In HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Current Version click on “DevicePath” and enter “C:\Drivers” (remember the entries must be separated by a semicolon). More info here: http://technet.microsoft.com/en-us/library/cc753716.aspx
From user comment:
To keep the drivers installed to the computer there has to be a option under “generalize” (Microsoft-Windows-PnpSysprep_neutral -> PersistAllDeviceInstalls=TRUE and DoNotCleanUpNonPresentDevices=TRUE. Otherwise if one of your device is off, the driver is uninstalled and etc.