0

How can I run a cmd script during windows setup somewhere between the beginning of phase 3 and the beginning of phase 5? I need to copy hardware dependent files from the USB drive to the C: drive before the hardware detection kicks in. I use wmic, which runs in WinPE, to determine the hardware.

EDIT: If anyone is interested...

In Boot.Wim\Index2:

  1. reneme setup.exe to usetup.exe
  2. Modify Boot.Wim-Index:2-Root\Windows\system32\startnet.cmd
    wpeinit
    start /w usetup.exe /unattend:yourfile.xml /noreboot
    do what you want here
    wpeutil reboot
    

Use that to manipulate files. If you need to work within windows, add your scripts to the \windows\setup\scripts\SetupComplete.cmd file.

Be advised, that SetupComplete.cmd runs hidden, so be sure it runs without intervention.

1 Answer 1

3

According to this Microsoft Technet article you can run a custom script at the end of Phase 3 by doing the following:

You can make further customizations after Windows Setup completes by adding commands to the %WINDIR%\Setup\Scripts\SetupComplete.cmd file. This file enables you to install additional applications, run custom Windows scripts (cscript/wscript), or make other modifications to the system before a user logs on.

Commands in the Setupcomplete.cmd file are executed with local system privilege.

After Windows is installed, but before the logon screen appears, Windows Setup searches for the SetupComplete.cmd file in the %WINDIR%\Setup\Scripts\ directory.

If a SetupComplete.cmd file is found, the file is executed. Otherwise, installation continues normally. Windows Setup logs the action in the Setupact.log file.

You cannot reboot the system and resume running SetupComplete.cmd.

Setup does not verify any exit codes or error levels in the script after executing SetupComplete.cmd.

The functionality of Setupcomplete.cmd differs from the RunSynchronous and RunAsynchronous commands in that Setupcomplete.cmd runs after Windows Setup completes while the RunSynchronous and RunAsynchronous commands run during Windows Setup.

So, whatever script you want to run simply needs to be added to a "SetupComplete.cmd" file and placed in the %WINDIR%\Setup\Scripts inside your Windows image. The installation process will automatically run it so long as it finds the script there.

(Sorry for the copy/paste, but there really isn't much else to it.)

Edit

As a note, if the files you are copying over are hardware driver files, you can simply add those to either the Windows PE image or the Windows image itself and not worry with a script. Here is the Microsoft Technet article that tells you how to do it. (I'm not going to copy/paste it as it is a bit too much.)

If it is just other general files (images, documents, etc.), you can also add those to whichever folder you want within the Windows image. Here is how to do it using DSIM: Microsoft Technet article The article is under the Windows 8/8.1 library, but it is the same steps for Windows 7.

I would avoid a script just for copying files (if that is all your script does). I would add the files or drivers to the image and then you don't have to worry about what happens if your script fails for some reason.

Edit 2

Per your comment below and that you stated you're using WMIC during WinPE to determine hardware, you might be able to add the script to WinPE as detailed in this Microsoft Technet article. I think this might be too early to copy the files over, but I would have to test to know for sure. I know I've added a driver for a network interface to a WinPE image, but that is a bit different from what you're doing.

However, I think your best option is to use Microsoft Deployment Toolkit (MDT) and set up your drivers based on hardware profiles and/or make/model of computer. It's designed for exactly this type of scenario and should let you customize what drivers are installed when and where. This can get a little more complicated than just using Windows AIK, but if your driver needs are this specific, I think you'll get better results.

The tutorials I followed when I first started using MDT are here:

  1. WindowsNetworking.com - Deploying Vista using AIK - While this is geared towards Vista most of the steps are the same for 7. Depending on how familiar you are with AIK you can skip to part 24 which starts talking about MDT.
  2. WindowsNetworking.com - Deploying 7 using AIK - This is almost a continuation of the previous link since he doesn't go through all the details of the first, just the changes between the Vista AIK and the 7 AIK. The section about managing drivers with MDT starts in part 23. I think parts 25 and 26 would be the most important to you.

I think this will give you the better option for deployment than using a script because I don't think you can run a custom script at the point you want to run it. I hope this helps you.

4
  • Thanks, but that runs after phase 5 and just prior to the first user login. I need it to run just prior to, or directly after the hardware detection, prior to the reboot. I have several different manufacturers and models, with hardware just similar enough, that windows sometimes installs the wrong drivers, if they are all available. So basically my script uses forfiles and pnputil to install the drivers in the %Manufacturer%\%model% directory from the USB drive.
    – Daro
    Commented Sep 18, 2015 at 15:22
  • See my updated answer.
    – Slicktrick
    Commented Sep 18, 2015 at 16:13
  • Your second edit looks very promising! We shall see...
    – Daro
    Commented Sep 18, 2015 at 17:00
  • Glad I could help.
    – Slicktrick
    Commented Sep 18, 2015 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .