Skip to content

SysPrep in Depth - Part 6 - Bringing Parts 1-5 Together⚓︎

September 28, 2007

Taking Parts 1-5 and Creating your First Image⚓︎

Bringing Parts 1-5 Together⚓︎

Now we have everything lined up we can talk about using a batch file to bring this all together. In this sample script I make use of the optional tool sync.exe from Mark Russinovich and do a few other things we have yet to talk about. Read over the script once and then I will explain as many questions as I can.

@echo Off
echo Before continuing please be sure that the pre-sysprep steps were followed.
echo --------------------- These steps are very important! --------------------
echo 1: The computer is no longer part of the domain.
echo 2: Restart the computer after dis-joining the domain.
echo 3: Using Device Manager uninstall all hardware possible.
echo 4: Close all open windows before continuing.
echo 5: Open c:\sysprep\sysprep.inf and read all notes.
echo Flushing data to disks (preliminary):
c:\sysprep\utils\sync.exe -r -e 1>nul 2>nul
echo Flushed...
echo Cleaning up old driver caches:
del /s /q c:\Drivers\infcache.1 1>nul 2>nul
echo Files cleaned...
echo Settings File Permissions...
cacls c:\sysprep /e /p "everyone":r 1>nul 2>nul
cacls c:\drivers /e /p "everyone":r 1>nul 2>nul
echo Permissions edited...
echo Deleting unwanted files:
del "c:\WINDOWS\system32\ReinstallBackups" /s /q 1>nul 2>nul
cd /d "c:\WINDOWS\system32\ReinstallBackups" 1>nul 2>nul
rmdir "c:\WINDOWS\system32\ReinstallBackups" /s /q 1>nul 2>nul
del "c:\WINDOWS\system32\dllcache" /s /q 1>nul 2>nul
echo Files deleted...
echo Cleaning unneeded registry items:
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\setup /v "Installation Sources" /t REG_MULTI_SZ /d C: /f
echo Registry has been cleaned...
echo Setting Sysprep Paths:
c:\sysprep\utils\spdrvscn.exe /p c:Drivers /e inf /d c:\sysprep\i386 /f /a /s /q
echo Paths set...
echo Closing open SMB connections:
net use * /delete /yes 1>nul 2>nul
echo Connections Closed...
echo Flushing data to disks (finalization):
c:\sysprep\utils\sync.exe -r -e 1>nul 2>nul
echo Flushed...
echo ------- Please read and follow these directions to finish syspreping! --------
echo 1: Run sysprep.exe and click ok to the warning.
echo 2: Select 'Use Mini-Setup' and 'Detect non-plug and play hardware'
echo 3: Select the shutdown mode
echo 4: Click Reseal
echo Other Notes:
echo 1: If you are testing sysprep and not planning on cloning this image to any
echo other PC's then you can check 'Don't reset grace period' and
echo 'Don't regenerate security ID's'
echo ----- Please remember this about Sysprep ------
echo Sysprep will only reset the grace period 3 times on an OS!
echo This means that after the 3rd time you will have to active windows before
echo you can even logon to the system.
echo This does not affect any other aspects of the clone, but it is worth
echo trying to avoid.

What does this all mean?⚓︎

I prefer to dis-join pc’s from the domain before running SysPrep, SysPrep does do this for you during its process so this is merely personal preference. Remember to also uninstall all the devices that you can in the Device Manager, right before running this script would be a great time to do this. You also want to have as little running as possible so close out all open windows and as many programs as you can out of the tray. Verify that antivirus programs are not scanning is always a good idea during the sysprep process. You should also open your sysprep.inf file, read any comments and make sure it has all the customizations you want in it. Don’t forget to check your OemPnPDriversPath value to make sure it is up to date.

Now we can get into what the batch file actually does. There are 8 steps to this batch file that actually have an effect on the PC:

  1. First off I run sync.exe and flush all data to the drive. This is just a precautionary measure but when you are making a clone to be deployed to 600+ computer you want to be as careful as possible.
  2. Now I start cleaning up all the driver cache files, starting with the infcache.1 files in our drivers folder.
  3. Now we set the permissions on both the sysprep and drivers folders so that we have no issues with sysprep not being able to use its drivers.
  4. For the next step we clean all the cached drivers that the current system has created just to make sure sysprep will always use our drivers folder we created.
  5. Change the “Installation Sources” registry key so that we know yet again no other drivers will be used.
  6. Run spdrvscn.exe to set yet another registry key to let sysprep know where we have all our drivers stored.
  7. Close all network connections just as another precautionary step.
  8. Run sync.exe one last time

Now we get a little notice as to what settings to run sysprep with to get the results we want. Remember that if you are making a clone of this PC, when it turns off is the time to pull the clone. You don’t want to let it turn back on and sysprep start-up until you have cloned this computer out to all your other computer.

Now What⚓︎

There are still further customizations that you can do to your image that we haven’t even talked about. I have mentioned that I will explain the whole PNPID issue and how to fix or avoid issues with it. I also touched on a way that you can have a script type in your product code for you if you don’t have a VLK. This isn’t very useful to most people because if you have 50+ computers you are cloning you probably already own a VLK, but there are people out there that don’t have the VLK and end up typing in 50 different product codes into 50 different computers. There is a legal way around having to type them in by hand actually, so keep checking back for a new SysPrep in Depth that explains this process.