GSS, Batch Scripts and Windows 7 Reimaging Step 1



This post represents Step 1 of my Windows 7 Re-imaging series. 


It deals with SysPrep and the unattend.xml file.

My SysPrep batch execution file looks like this:



TITLE Run SYSPREP
::Deletes registry keys when computer has been joined to the domain.
::Copies the latest unattend.xml to sysprep directory and deletes latest Sysprep_succeeded.tag file
::Calls the cleanup files
::Runs Sysprep and applies the latest unattend.xml and shuts down
::computer is now PENDING GHOST IMAGE SNAPSHOT BASELINE!

::Delete DOD Logon banner to facilitate autologon
::ONLY NEEDED IF IMAGE HAS BEEN JOINED TO DOMAIN!*******************
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system" /v LegalNoticeText /f
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system" /v legalnoticecaption /f

::Copy unattend.xml and delete Sysprep_succeeded.tag file
copy /Y C:\rename_computer\unattend.xml %SystemRoot%\System32\sysprep
del /S %SystemRoot%\System32\Sysprep_succeeded.tag /Q

::Clean up junk files
start /wait call C:\rename_computer\Cleanup\iecache_temp_recycbin_clean.bat

cd \
cd windows\system32\sysprep

sysprep.exe /generalize /oobe /reboot /unattend:unattend.xml

exit



The sysprep_oobe.bat script is pretty self explanatory. The registry delete keys are only applicable because this image is based from a DoD provided image which has a logon consent banner. This banner will prevent the image from being fully automated because the user will have to press ‘OK’ in order for the image to autologon into the OS. You may or may not have a logon consent banner on your native image. It probably would be set on your Default Domain Policy, though.

The copy unattend.xml and delete Sysprep_succeeded.tag statements are to ensure the latest unattend.xml file is used and the previous Sysprep_succeeded.tag (purely optional) is deleted.

I have some cleanup files that run (iecache_temp_recycbin_clean.bat) to remove unnecessary files and junk that should not be needed on any baseline image. This cleanup script is purely optional.

Contents of iecache_temp_recycbin_clean.bat:



C:\rename_computer\Cleanup\IECache.exe /delete
C:\rename_computer\Cleanup\CleanUp.exe /y /a /q /p:C:\Windows\Temp
C:\rename_computer\Cleanup\psloglist -c application /accepteula
C:\rename_computer\Cleanup\psloglist -c security /accepteula
C:\rename_computer\Cleanup\psloglist -c system /accepteula
C:\rename_computer\Cleanup\psloglist -c Osession /accepteula
del /S /Q /F "C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"
C:\rename_computer\Cleanup\EmptyRecycleBin.exe /q
exit


The files are all executables that can be run from the command-line.
psloglist.exe
CleanUp.exe

EmptyRecycleBin.exe
IECache.exe

The script executes from the 32 bit SysPrep directory with the listed switches. The /reboot switch is used instead of the /shutdown switch because of testing. When the image is ready to be captured, I can change it to /shutdown.

The unattend.xml file is pretty basic except for the following sections (this is not the entire file). I suggest keeping this file as clean as possible. I only posted the OOBE>>Microsoft-Windows-Shell-Setup>>Autologon>>FirstLogonCommands section from the full unattend.xml:


<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <HideEULAPage>true</HideEULAPage>
                <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
                <NetworkLocation>Work</NetworkLocation>
                <ProtectYourPC>1</ProtectYourPC>
            </OOBE>
            </AutoLogon>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <RequiresUserInput>false</RequiresUserInput>
                    <Order>1</Order>
                    <Description>Install Key</Description>
                    <CommandLine>cscript //b c:\windows\system32\slmgr.vbs /ipk 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH </CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>cscript //b c:\windows\system32\slmgr.vbs /ato</CommandLine>
                    <Order>2</Order>
                    <RequiresUserInput>false</RequiresUserInput>
                    <Description>Register OS</Description>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>C:\rename_computer\pcrenamed_from_pdq2.bat</CommandLine>
                    <Description>Sysprep reboot</Description>
                    <RequiresUserInput>false</RequiresUserInput>
                    <Order>3</Order>
                </SynchronousCommand>
            </FirstLogonCommands>



The slmgr.vbs cscripts have NOT been thoroughly tested. Please go here for details of the slmgr.vbs commands. However, my clients do report that Windows 7 is activated. The product key used here is available from Microsoft.
The Order 3 command is the important one here. It runs my pcrenamed_from_pdq2.bat script to start my auto-renaming process. 

That concludes Step 1 of this series. 

There are three steps in this series and an intro. Please review them all to have a complete Windows 7 upgrade re-imaging solution.

Please see Step 2 of this series here, GSS, Batch Scripts and Windows 7 Reimaging Step 2.




Comments