SysPrep in Depth - Part 4 - Cleaning Up Unneeded Drivers⚓︎
September 28, 2007
Cleaning Up Those Unneeded Drivers⚓︎
Why We Need To Clean Up Our Drivers⚓︎
When Windows XP detects new hardware it starts looking for drivers in some default areas before it prompts the user for drivers. This feature is great, but there is one huge setback to it, companies that write driver inf’s that are “generic”. I will get into PNPID’s in another issue but for now lets just say that company A writes a driver for a video card with the PNPID of 1234-1234-1234-1234 and also writes a driver for the PNPID 1234-5678-5678-5678. The then come out with an inf that has a generic PNPID contained in it for all 1234-xxxx-xxxx-xxxx cards.
This is very common for hardware makers to do as they now have one inf file that often even points to the same .dll and .sys files and will “work” with any of their hardware. They do this so that all they have to do is update the .dll and .sys files and hand them off to you and they will always work, it’s less work on their side.
The issue with doing this is that card 1234-5678-5678-5678 does require its specific driver and not this “generic” driver, see where this is going yet? So we have a computer with the video card PNPID of 1234-1234-1234-1234 and we clone it to a computer with a video card with the PNPID of 1234-5678-5678-5678, what does Windows XP do? First off it will go looking for the driver and find that the driver that is already installed will work for this new card and will start using this generic driver. Windows XP has now installed the wrong driver because the driver said it was good for this card. Again, I will go into more depth with this in a later issue but this is one of the underlying issues for cloning to different sets of hardware.
How We Prevent This Issue⚓︎
So how do you get around this? Well the first step would be to delete all the cached files on the base image PC. There are two folders in which cached drivers will often be found, c:\Windows\System32\ReinstallBackups and C:\Windows\System32\DLLCache. Using some quick command lines we can easily delete these temporary files.
del "c:\WINDOWS\system32\ReinstallBackups" /s /q cd /d "c:\WINDOWS\system32\ReinstallBackups" rmdir "c:\WINDOWS\system32\ReinstallBackups" /s /q del "c:\WINDOWS\system32\dllcache" /s /q
The second step we can do is to uninstall all unneeded drivers from the computer right before SysPrep’ing the PC. To do this open up the Device Manager and uninstall as many pieces of hardware as you can but be careful since there are a few you might not want to remove, ie the mouse and keyboard. Some of the key devices to uninstall are the hard drives, ide controllers, SATA controllers, video drivers, monitor drivers and network cards as these will often be different on our destination PC. Once you do this step you cannot reboot until after SysPrep has been run and you image the PC as XP will reinstall all these drivers on the next reboot and go looking for all the drivers we just deleted.
The third step would be to edit a registry key that some manufacturers put in the registry to point SysPrep to a custom driver directory. During the SysPrep process SysPrep will check this folder and use drivers from this directory before using the drivers you have included. If you are still collecting drivers you might want to see if this key exists, if it does separate out each driver and copy them to your drivers you created on your system drive. I normally set this key to my system drive so that there is no confusion as to where SysPrep will look for drivers, and by pointing it to the root of the system drive you almost guarantee there are no drivers in the root.
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\setup /v "Installation Sources" /t REG_MULTI_SZ /d C: /f
SysPrep, Reboot and Image⚓︎
After you have done these steps you are ready to run SysPrep and grab the image from your base PC. Remember that your computer now has very few of the needed drivers for the hardware installed so be sure you have created a drivers folder and let SysPrep know where these drivers are. Please see my SysPrep in Depth - Part 1 - Adding Drivers to our Image PC for more directions on how to do this.
C ä n n e, 10/19/2007
[…] should remove also the following directory (see David Remy’s blog post about […]
What about “sysprep -clean”? I havent been able to figure out exactly what this does and when to run it. I tried to run it before doing a sysprep -reseal, but then I got an error about “Unable to update the registry”, and from what I found on google, this means theres an issue with the SysprepMassStorage section, not sure why though.. is sysprep -clean meant to be run AFTER your image is restored and sysprep mini setup runs?
Johan Bezem, 04/15/2009
[…] - Verifying SysPrep And Driver File Permissions SysPrep in Depth - Part 3 - SysPrep.inf and HAL’s SysPrep in Depth - Part 4 - Cleaning Up Unneeded Drivers SysPrep in Depth - Part 5 - Customizing Sysprep.inf SysPrep in Depth - Part 5 addition 1 - […]
David, how about a few devcon commands?
devcon remove =media devcon remove =display devcon remove =usb devcon remove =monitor