How to run commands after Windows 7 deployment using SetupComplete.cmd

   Posted February 22, 2012 by Jimmy Selix in Windows 7, Windows installation

This guide will explain how to utilize a SetupComplete.cmd batch file in a Windows 7 image.  The SetupComplete.cmd batch file can be used to run commands after an image has been deployed or restored.  This can facilitate the cleanup of unattend files, the installation of drivers, or other common post-deployment tasks.

1. On the Windows 7 image, we will need to be logged in as either the administrator account or your installer account with administrator permissions.

2. Open up Windows Explorer and browse to C:\Windows\Setup

3. You will notice that you may or may have a setup folder. We will want to create a new folder in here called Scripts as in C:\Windows\Setup\Scripts.

4. Once we have created the Scripts folder, go into it to create a new text file. Rename it as SetupComplete.cmd.

5. Right-Click on the SetupComplete.cmd and choose the Edit command.  This will open the file in Notepad.

6.  Add your entries in here and then save the file.  These commands are run after setup completes but before unattend executes any synchronous or asynchronous commands.

For example, if you are deploying images using an unattend.xml file, we will probably want to remove that file since it can contain sensitive data such as the Windows 7 CD Key and passwords.  So for my example, I will cleanup all of the unattend files used for deploying by adding these commands:

del /q /f c:\windows\system32\sysprep\unattend.xml
del /q /f c:\windows\panther\unattend.xml

You can also silently install drivers using a silent flag or even rerun the Windows Assessment Utility (which checks to see if you can enable Aero or not) by adding this line:

winsat formal

If you have the Novell Client installed in your image, you can have it apply a settings file (MNsettings) by adding this line:

c:\novell\client\setup.exe /NCPF:MNsettings.txt

This SetupComplete.cmd file will run after setup is completed and before any synchronous commands are executed in the unattend.xml.

7. Finally, sysprep your image. You can also add this file after you have sysprepped and captured the image if you are using .wim images and using imagex.

SetupComplete.cmd Essentials

– Location:  C:\Windows\Setup\Scripts\SetupComplete.cmd
– Runs as the system user account
– Runs after setup completes but before any synchronous or asynchronous commands are executed in the unattend.xml file
– Requires use of a full path for the location to .exe or .msi files


About Jimmy Selix

Jimmy Selix is an early adopter that loves to be one of the first on the block to have the latest and greatest in technology and gadgets. Another love of his is being able to share his knowledge to others seeking it. Feel free to drop any comments or questions that you may have.
View more articles by Jimmy Selix

The Conversation

Follow the reactions below and share your own thoughts.