How to: Export all drivers and reinstall after clean Win install or make a Win image with those drivers

Come here to find solutions to difficult problems!
Post Reply
hsehestedt
Posts: 91
Joined: Sat Mar 04, 2023 4:36 am
Been thanked: 12 times

How to: Export all drivers and reinstall after clean Win install or make a Win image with those drivers

Post by hsehestedt »

Do you plan on reinstalling Windows from scratch? Did you know that you can modify your Windows installation disk to include all drivers for your system?

Before we begin, a couple of notes: First, this procedure is not difficult, but there are a lot of steps so this may take a while. I suggest this procedure only for those who may want to reinstall Windows frequently such as if you are doing a lot of testing with your system or if you are a Windows enthusiast curious about how to add the system drivers to your Windows image. Otherwise, it may simply be much easier to make a backup copy of all your drivers on the system, then install Windows clean as you would normally do, and then re-import all the drivers. For this reason, I will show you how to perform both procedures.

Part 1 - This will show you how to export and save all your drivers, then reinstall them after a clean install. This procedure is extremely simple and fast.

Part 2 - This is the detailed procedure that will show you how to customize your Windows media to include all the drivers for your system. This procedure has quite a few steps, but I'll guide you through them step-by-step. It's easy, but some of the steps can be a little time consuming and requires you to install the Windows ADK (Assessment and Deployment Kit).


****************************************************
* PART 1 - Make a Backup Copy of Your Drivers and *
* Re-install Them After a Clean Install of Windows *
****************************************************

We'll start by making a backup of all the drivers on your system. Just follow these steps:

1) Open a command prompt as administrator.

2) Create a folder to which you can save your drivers and export your system drivers by running the commands below. That folder can be on your internal drive, an external drive, a thumb drive, etc. In the example below, note that I am using C:\Project\Exported_Drivers:

MD "C:\Project\Exported_Drivers"
pnputil /export-driver * "C:\Project\Exported_Drivers"

3) You should now copy the Exported_Drivers folder to a USB Flash Drive (UFD), external drive, etc. so that it will be available to you in the future if you reinstall Windows, or if your hard disk crashes, etc.

That is all! The next steps show you how to reinstall the drivers after you perform a clean install.

4) Assuming that you have already reinstalled Windows, plug in the drive or UFD on which you have the previously exported drivers.

5) Do either one of these:

A) Open Device Manager, at the top of the device tree, right-click on the computer name, select "Add Drivers", browse to the location where you have the saved drivers, check the box that says "Include subfolders", click on "Next".

OR

B) Open an elevated command prompt and run this command:

pnputil /add-driver "D:\Exported_Drivers\*.inf" /subdirs /install

NOTE: D:\Exported_Drivers is the location of the drivers. Change this to the location where you have the drivers. Please also note that this may take several minutes and that the screen may flash or go blank temporarily at the point where the display drivers are being installed. This is normal.

Done! That's all there is to reinstalling all your system drivers.


***************************************************
* PART 2 - Inject Drivers Into Your Windows Image *
***************************************************

1) Start by following steps 1 - 3 of the PART 1 procedure above. This will export all of the drivers from your system. Once you have completed those steps, come back here and continue with step 2 below.

2) Create a folder to which you can copy the contents of your Windows install media. In this example, I will use "C:\Project\ISO_Files".

3) Create another folder to which we can temporarily mount the Windows "install.wim" file. I will use "C:\Project\Mount".

IMPORTANT: Microsoft distributes Windows images that may contain a file named "install.wim" or it may contain a file named "install.esd". This procedure will use a Microsoft utility called "DISM" which requires that you have an image with an install.wim, not an install.esd.

To check which file your image has has follow these steps:

A) Double-click the ISO image file. This will mount it to a drive letter, much like inserting a DVD into a DVD drive on your computer.

B) In File Explorer, look at the drive letter to which your ISO image was mounted and go into the "sources" folder. Within that folder you will find either an install.wim or an install.esd file.

C) If you see an install.wim file, skip to step "F" below. If you see an install.esd file, continue with step "D".

D) Go to the Microsoft Windows 11 download page located here: https://www.microsoft.com/en-us/softwar ... /windows11

E) Skip down to the section that says "Download Windows 11 Disk Image (ISO) for x64 devices", make a selection in the box that says "Select Download", then click on the "Download" button. Select the desired language and then click on "Confirm". This will download an ISO image with an install.wim file.

F) You can now unmount the image that I asked you to mount in step A. To do so, in File Explorer, find the drive letter of the mounted image, right-click it, and choose "Eject".

4) We will now install the Windows ADK (Assessment and Deployment Kit). You can install it from here:

https://learn.microsoft.com/en-us/windo ... dk-install

NOTE: When installing the ADK, you will be shown a list of items that can be installed. You can choose to install only the Deployment Tools from this list. This makes the install quick and very small.

5) Open a command prompt by running the "Deployment and Imaging Tools Environment" in elevated mode (as Administrator). You will find this item in Start > All Apps > Windows Kits. Again, make sure to run this elevated (as Administrator).

TIP: When you open the Deployment and Imaging Tools Environment, you can issue a "CD \" to change paths to the root of the volume. This makes the prompt at the command line much shorter and less obtrusive while you are working. Leave this window open until the very end. We will run all of the needed commands from the Deployment and Imaging Tools Environment.

NOTE: This environment is basically like any other command prompt, except that various variables and paths are set so that the tools we need such as DISM.exe and OSCDIMG.exe are in the path, ensuring that the latest version of these utilities is run from the ADK location.

6) We will now create the folders that we need for this project by running these commands. Note that you should have already created some of these folders in the above steps so running these commands my give you an error message stating that those folders already exist. That's perfectly okay.

MD "C:\Project\ISO_Files"
MD "C:\Project\Mount"
MD "C:\Project\Exported_Drivers"

7) At this point, I would strongly suggest creating an exception for C:\Project in your antivirus software. I have seen many cases of problems with this procedure completing successfully if this is not done. As an alternative, you could temporarily disable real-time virus scanning until you are done.

If you are using Windows Security, you can set an exclusion by going here (this assumes Win 11 22H2): Settings > Privacy & security > Windows security > Open Windows Security > Virus and threat protection > Under "Virus and threat protection settings" select "Manage settings" > Add or remove exclusions.

For other AV programs, see instructions for that software.

8) Copy or move all the drivers that you exported earlier to C:\Project\Exported_Drivers.

9) Mount your Windows ISO image by double clicking it in File Explorer. Copy ALL files and folders from that image to C:\Project\ISO_Files.

10) Unmount the Windows image. You can do this by going into File Explorer and opening "This PC". Right-click on the drive letter for your mounted Windows image, select Eject.

11) We now need to determine what edition of Windows you have on your PC and where this edition is located in your Windows image. Begin by going Windows Settings > System > About. Under the "Windows specifications" section it will list the "Edition". In all liklihood, this will be either Windows 11 Home or Windows 11 Pro. Take note of the edition that you have installed.

12) Check what editions are available in your Windows image by running this command:

DISM /Get-WimInfo /WimFile:"C:\Project\ISO_Files\Sources\install.wim"

You should see output that looks something like this:

Deployment Image Servicing and Management tool
Version: 10.0.22621.1

Details for image : C:\Project\ISO_Files\Sources\install.wim

Index : 1
Name : Windows 11 Home
Description : Windows 11 Home
Size : 16,168,829,996 bytes

Index : 2
Name : Windows 11 Home N
Description : Windows 11 Home N
Size : 15,506,889,019 bytes

Index : 3
Name : Windows 11 Home Single Language
Description : Windows 11 Home Single Language
Size : 16,153,401,297 bytes

Index : 4
Name : Windows 11 Education
Description : Windows 11 Education
Size : 16,463,631,301 bytes

Index : 5
Name : Windows 11 Education N
Description : Windows 11 Education N
Size : 15,808,633,936 bytes

Index : 6
Name : Windows 11 Pro
Description : Windows 11 Pro
Size : 16,479,089,353 bytes
.
.
.

Note that the above is only a partial output, but it is enough for me to explain what we are looking for. Note that each edition of Windows has a unique index number. In the above example, Windows 11 Home is index 1 and Windows 11 Pro is index 6. Make a note of the index number associated with the edition of Windows that is installed on your system as you determined above in step 11. In the steps that follow, I am making the assumption that you have Windows 11 Pro which in the output above corresponds with index 6. As a result, I will use index 6 for any commands that reference an index number. Please alter this if you need to do so for your specific situation.

13) Mount the install.wim by running the command below. Remember to change the index number if needed to match your situation.:

DISM /Mount-Image /ImageFile:"C:\Project\ISO_Files\Sources\install.wim" /Index:6 /MountDir:"C:\Project\Mount"

Wait for the image to be mounted, then continue to step 14.

14) Inject the drivers by running this command:

DISM /Image:"C:\Project\Mount" /Add-Driver /Driver:"C:\Project\Exported_Drivers" /Recurse

When completed, continue with step 15.

15) Unmount the image:

DISM /Unmount-Image /MountDir:"C:\Project\Mount" /Commit

Once done unmounting, continue to step 16.

16) Make final ISO image:

Caution: This is a long command and there places in the command where you may be tempted to add a space where no space should be used. To avoid errors I sugest copying and pasting this command, then modify if needed before running the command. Also, read the note below the command before you actually run it.

oscdimg -m -o -u2 -udfver102 -l"Win 11 for Mini PC" -bootdata:2#p0,e,b"c:\Project\ISO_Files\boot\etfsboot.com"#pEF,e,b"c:\Project\ISO_Files\efi\microsoft\boot\efisys.bin" "c:\Project\ISO_Files" "c:\Project\Windows.iso"

NOTE: The "Win 11 for Mini PC" is the volume name that will be assigned to the image. You can replace this text with anything that you want, just be aware that you are limited to 32 characters. Also, Windows.iso is the name that we are giving the ISO image file that we are creating. You can change that name to anything you want.

Status Check

At this point you have a new Windows image that includes the drivers for your system. Please note that even if the original Windows image had multiple editions of Windows (Windows Home, Pro, etc.), the new image will contain ONLY the image associated with the index number that you specified in the commands above. For example, if you injected the drivers into Windows 11 Pro, your new image will contain ONLY Windows 11 Pro. Also, in that new ISO image, since we only have a single Windows edition, that edition of Windows will have an index of 1. This is not critical to remember, just something that you may wish to know.

I suggest copying or moving C:\Project\Windows.ISO (or whatever you named it) to a location where you can safely keep it. Once you have done so, you can delete the folder C:\Project along with all files and subfolders.

In the next steps, you will create a bootable USB Flash Disk (UFD). To do this, follow these steps:

Note: Some of you may note that there are some easier ways to create the flash drive, but the procedure I provide has some distinct advantages. For example, this procedure creates a flash disk that will work on any system including old BIOS based systems (as opposed to UEFI based systems). Also, some systems don't like to boot from flash disks formatted with NTFS. This will work around that.

17) Select a flash drive of at least 8 GB in size and no larger than 2 TB and plug it into a USB port. If your system has a large number of drivers, it's possible that you may need a 16 GB flash drive rather than 8 GB as a minimum.

IMPORTANT: Make sure there is nothing you need to keep on this UFD - all data on it will be erased!

18) Run the following command:

diskpart

Once diskpart has started, run this command:

list disk

From the size of the disks, try to determine which disk ID is your thumb drive. If that is not enough information, run these commands to get more detail on the disk. In this example, I want more info on disk 4:

select disk 4
detail disk

Here is some sample output:

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
Disk 1 Online 3726 GB 0 B *
Disk 2 Online 465 GB 1024 KB *
Disk 3 Online 7452 GB 0 B *
Disk 4 Online 238 GB 0 B

DISKPART> select disk 4

Disk 4 is now the selected disk.

DISKPART> detail disk

SanDisk Extreme Pro USB Device
Disk ID: DC727760
Type : USB
Status : Online
Path : 0
Target : 0
LUN ID : 0
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 7 Z My Software NTFS Removable 238 GB Healthy
C:\MountPoints\My Software\

When you determine the correct disk, run the commands below. I am assuming disk 5 in the following example, but make sure to substitute the correct number for your UFD. Please also note that there is an issue with diskpart where you may get an error message after you run the "clean" command. If that happens, simply run "clean" a second time. Finally, the "assign" commands will assign the next available drive letter. If you want to assign specific drives letters, for example E:, use the command "assign letter=E".

IMPORTANT: Once again, make sure you select the correct disk number because these commands will wipe the contents of the disk that you select. If you are not certain, you can close the command prompt to abort the procedure now.

select disk 5
clean
convert mbr
create partition primary size=2000
active
format fs=fat32 quick
assign
create partition primary
format fs=ntfs quick
assign
exit

19) Double-click the ISO image file that we created earlier (Windows.ISO) in File Explorer. This will mount that image to a drive letter. Take note of the drive letter to which it is mounted. In the commands below, I am using the drive letter H:.

20) We will now copy files from the source to the two partitions on the thumb drive. To be clear, all the files and folders that you are being asked to copy come from your mounted ISO image (H: in this example). Make sure to use the correct letter in place of H: for your situation.

Create a text file called ei.cfg. We will use that below. Place the following 2 lines into that file:

[Channel]
Retail

Notes about ei.cfg: Let's say that you have a computer that shipped with Windows Home edition, but you upgraded to Pro. You may find that when you try to perform a clean install, Windows simply starts installing Home and doesn't even show you the menu from which you can select other editions. By placing this file in the sources folder, we prevent that from happening. This happens because Windows setup reads a signature in the BIOS that tells setup which edition of Windows the system was shipped with. This is especially important in cases like this where we only have a single edition of Windows in the image. You want to make sure that this edition is available when installing from your media.

Follow these steps to copy files to your thumb drive:

• Copy all files and folders EXCEPT the \sources folder to the FAT32 partition (the first, smaller partition).

• Create a folder called sources on the FAT32 partition.

• Copy the file \sources\boot.wim to the FAT32 partition \sources folder.

• Create a folder called sources on the NTFS partition (the second, larger partition).

• Copy all files and folders from the \sources folder EXCEPT boot.wim to the \sources folder on the NTFS partition.

• Copy the ei.cfg file that you created to the \sources folder of the NTFS partition.

Done! At this point, you should have a bootable thumb drive.

NOTE: When booting you may be presented with an option to boot either the FAT32 or the NTFS partition. Choose the FAT32 partition. If it is not clear which one the FAT32 partition is, simply try either. If it doesn't work, reboot and try the other. Usually, the FAT32 partition will be the first or only partition shown by your system.

At this time, feel free to reenable your Antivirus software if you disabled it. If you set an exclusion, you can delete that exclusion now if you wish to do so.

If you encounter any difficulties, please let me know and I will be happy to help.

Y2kdancr2
Posts: 2
Joined: Sat Apr 01, 2023 2:30 pm

Re: How to: Export all drivers and reinstall after clean Win install or make a Win image with those drivers

Post by Y2kdancr2 »

This worked perfectly and allowed me to upgrade my AK1Pro SSD to a WD_Black 1 TB NVMe.
I had to read the existing windows 11 Pro product key from the registry, So I could reinstall Windows 11 Pro after following the noted steps.

Thanks for posting these steps.

LW
User avatar
barry777
Posts: 1132
Joined: Thu Mar 02, 2023 1:08 am
Has thanked: 35 times
Been thanked: 87 times

Re: How to: Export all drivers and reinstall after clean Win install or make a Win image with those drivers

Post by barry777 »

Y2kdancr2 wrote: Sat Apr 01, 2023 2:39 pm This worked perfectly and allowed me to upgrade my AK1Pro SSD to a WD_Black 1 TB NVMe.
I had to read the existing windows 11 Pro product key from the registry, So I could reinstall Windows 11 Pro after following the noted steps.

Thanks for posting these steps.

LW
I consulted with product technicians, AK1 Pro does not support NVME at present. How did you achieve it?
Post Reply

Return to “Computer Technology Zone”