Using imagex.exe, Sysprep and WinPE to clone a Windows 7 PC

This guide is a step-by-step or a walkthrough to assist you in cloning a Windows 7 machine with all its Windows Updates, Software and settings, so that you can deploy onto another PC/computer without having to sit in front of it and manually install the many software packages one by one. Also if you have download limits with your internet connection like my Dad does, this will save double downloading of the same thing. E.g. Windows Updates and Office Updates.

Tools you will need for this are as follows:

  • A WinPE disk with imagex.exe included on it. You can either make this yourself, or download my pre-made Windows 7 WinPE version in ISO format from here. My version is 64-bit, which should be okay as most machines are 64-bit these days. If you want to make this yourself, it’s a bit tricky, you will need the Windows (AIK) Automated Installation Kit and then you follow this guide.
  • A Windows 7 installation DVD, either as a hard copy or ISO file. Try to match the version of Windows 7 you have, e.g. Ultimate, Professional, Home Premium or Enterprise. If you are using a physical PC, then you’ll need the hard copy, so if you have the ISO file only, you’ll need to burn this to DVD.
  • An alternative form of storage, e.g. external USB drive. This USB drive will need to be fairly large, the same, if not bigger than the C:\ drive of the machine that you want to take an image of. Imagex.exe outputs the image to a .WIM file which is single instance, however you will need enough space, just in case.
  • You will need to be familiar with your computer and which function key you need to press at start-up to bring up the different boot options. E.g. some machines require you to hit F12, then this will give you the option of booting from the CD/DVD ROM. Make sure you are familiar with the source and target machine’s boot device start options.

Sysprep source PC

To get the source PC ready so that you can take an image of it with imagex, you will need to sysprep it. In a nutshell, sysprep puts the Windows state one step back in the installation phase without affecting the data or software loaded. This ensures that after you take an image, once you load the image onto other machines, the image will boot more successfully without being dependant on having the same underlining hardware.

  • Step one of the systprep process means that you need to get everything ready, complete installing all the applications, download all updates to everything, Windows and Office updates etc. Remove any sensitive information.
  • Run Sysprep by running the sysprep.exe file located "C:\Windows\System32\Sysprep\sysprep.exe"
  • Choose options as per the image above, and then click OK. Sysprep will take about 5-10 minutes and will shutdown upon competition. When the computer shuts down, don’t power it back up, as you will need to first boot from the CD/DVD ROM using the WinPE CD.
  • The sysprep log can be found C:\Windows\System32\Sysprep\Panther. After executing sysprep, you might get an error for instance "A fatal error occurred while trying to sysprep the machine", also you might see the following errors in the sysprep log file.
    • [0x0f0070] SYSPRP RunExternalDlls:An error occurred while running registry sysprep DLLs, halting sysprep execution. dwRet = -2147024864[gle=0x00000020]
    • [0x0f00a8] SYSPRP WinMain:Hit failure while processing sysprep cleanup providers; hr = 0x80070020[gle=0x00000020]

    This error can be fixed by stopping and disabling the Windows Media Player Network Sharing Service under services in Windows.

Capture image of the source PC

Next you will want to use imagex and capture an image of the source PC which is in a sysprep state.

  • While the source machine is shutdown, plug into the external USB drive.
  • Start up the source machine, but make sure you quickly (before Windows loads) hit the correct function key, e.g. F12 which will give you the correct boot device options. You will want to insert the WinPE CD and boot from this device. Note, if you miss this boot device option and Windows starts loading, you will need to let it load fully and restart the whole sysprep process again.
  • Once the machine starts booting from the CD/DVD ROM, You will see the message "Press any key to boot from CD or DVD, press any key". Press any key.
  • Once WinPE has loaded, you will see just a command prompt window like this.
  • From here, navigate to each different drive looking for which drive contains the imagex.exe utility, also the Windows drive that you want to capture. First you’ll need to make note of the drive that contains the imagex.exe utility, start with drive letter c: and work your way up. Below is an example, type in e: at the prompt, hit enter. Then get a directory listing, type in dir and hit enter. You are looking for imagex.exe. Once found, make note of that drive.
  • The next drive you will need to make note of if the drive that you want to capture. This is the drive which you have run sysprep against. Again, cycle through the drive letters. For each drive letter, you want to change the directory structure to C:\Windows\System32\Sysprep. To change the directory, run the command cd (change directory), so you would run cd C:\Windows\System32\Sysprep and hit enter. Note, not all drives will have this location, so move to the next drive in this instance. You are looking for the drive which has the file Sysprep_succeeded.tag. Once found, make a note of this drive letter, this will be the source drive letter. In this example, my source drive letter is C:
  • Next you will need to cycle through the drive letters once again finding your external USB drive. Tip, you can skip e: drive and c: drive, as you know these are the imagex.exe and source drive respectively. Once you have found the drive letter of the external USB drive, make a note of this as well.
  • Next, take an image of the source machine.
    • Change the drive to the drive which contains imagex.exe, for example, type e: and hit enter. Then enter the following command imagex /capture c: d:\image.wim "ImageName" /compress fast /verify where C: is the source drive and D: is the USB drive.

  • Once this has finished, restart the source machine and start it normally.

Apply the image on the target PC

To apply the image on the target machine, it’s mostly the reverse of the previous step.

  • While the target machine is shutdown, plug into the external USB drive.
  • Start up the source machine, but make sure you quickly hit the correct function key, e.g. F12 which will give you the correct boot device options. You will want to insert the WinPE CD and boot from this device.
  • You will see the message "Press any key to boot from CD or DVD, press any key.
  • Once WinPE has loaded, you will see just a command prompt window like this.
  • Similar to the steps above, cycle through the drive and make note of drive containing the imagex.exe file, your external USB drive and the target drive. Making note of the target drive is a little more complicated, you can use DISKPART to help find it. Run Diskpart at the command prompt by typing diskpart and hitting enter.

    After DISKPART loads, type in list vol and hit enter.

    You will have a good idea of the target drive by looking at the size column. In my example, my target drive on the target machine is drive c:

  • Also, while you’re in DISKPART, run the following commands hitting enter after each one to prepare your target drive otherwise after booting from the newly loaded image, it might hang at the stage "Setup is starting services".
    • list disk (To list the target disks. Make note of the disk which you want to use as the target OS (operating system) disk)
    • select disk 0 (Your disk number maybe different)
    • clean
    • CREATE PARTITION PRIMARY
    • format quick fs=ntfs label="OS"
    • assign letter="c"
    • active
  • Exit out of DISKPART by running the command exit and hit enter.
  • Apply the source image onto the target machine by running the command imagex /apply d:\image.wim 1 c:\ /verify where d: is your external USB drive and c:\ is your target OS drive.
  • Once this is complete, remove the external USB drive and the WinPE CD and shut down the target machine.

Starting up the target machine for the first time

When starting the newly imaged target machine for the first time, you might receive an error "BOOTMGR is missing"

This can be fixed using the standard Windows 7 installation DVD media.

  • Boot the target machine from the Windows 7 installation DVD. You might need to choose the boot device by hitting the correct function key, e.g. F12.
  • Once the target machine boots from the CD/DVD ROM, a couple of seconds later press any key to boot from the DVD.
  • Select the correct Time and currency format, and click Next…
  • Choose the option to Repair your computer.
  • Let it search for Windows installations
  • Once it finds the Windows installation, click Repair and restart.

Computers and Internet Uncategorized

23 Comments Leave a comment

  1. Seriously ^^^WTF iPad? iPads suck, go thank your sister.

    Anyway on topic. To the blogger Marc, thank you so much for your blog and more so to your upload of the 64Bit WinPE iso with ImageX. You have no idea how long I had been searching for that. I even resorted to torrent sites. I needed it cause I didn’t have time to install and setup WAIK on my own PC. Everywhere I looked and every download I searched for ended up having 32Bit versions which is not what I needed.

    So thank you for that alone. The blog you have written is very well structured and is not confusing to read. Clear, concise with screen shots where needed. I may take a look at the other stuff you have up in your blog.

    Regards,

    James

  2. Hi,
    Try this process of clone a windows 7,
    When i restore in the target PC, SQL Server database permission problems are there. there anyway to clear it.

    • ramkumarchandran, where is the SQL database located? Is it on the same drive as the hard the syspreped system? Your NTUser and account should all be the same, so there should be no reason why you can’t access the database anyway? That of course unless a.) The PC you imaged from is still logged in and reading the database? b). That the new generated hardware UUID is different to the previous image, so SQL server may see that this is an unauthorised machine attempting to gain access. You will probably need to remove and re-add the credentials to the SQL dashboard to log in again. I hope that you have a secondary access point for SQL server? As in a local admin account? If not you may have to generate the hardware UUID into the registry your self so that they match again? I am not certain of how to do this, but you may need to check on some specialised SQL forums?

      Post a title: Changed hardware UUID causes permissions denied in SQL server

      • SQL server worked after removing and re-add the credentials. In addition , in SQL server configuration manager i changed log on to “Network Service”

      • Ah great! It’s good to know the simple solution was the right solution. Thanks for responding back to share. Even though this isn’t my blog I’m sure other readers who come across it will appreciate the information shared. I don’t know how many times I’ve visited blogs and have “maybe” found a solution to an IT problem yet the person who experienced the troubles who was looking for answers never bothers to respond in the last instance and you’re left wondering “Did that actually work? ” worse when it’s a forum that you need to sign up to in other to respond or necrobump the old thread. Trust me when I’ve exhausted all options I have eventually opt for the last mentioned lol.

  3. Sorry it’s James the same person who posted above, I just logged in with the incorrect account. My apologies.

    To the OP. I have now generated a very very useful WinPE with a heap of tools. Windows Startmenu, Windows explorer, Partitioning tools, recovery tools and so on. I’ve now become a wiz with WinPE :)

  4. Hi thank you very much for your guide…I work at a school and we have just been given 30 Windows 7 computers…obviously this guide saved me a lot of time and effort!

  5. I think you can get rid of the BOOTMGR IS MISSING and avoid having to boot to the Windows 7 disc and do the repair. There could be 2 reasons why you get this. I noticed that you are only applying 1 .WIM file to the PC and doing it as your C. What I have found with Win 7 is if you build it from scratch and blow away all partitions on the drive that Windows will create a 100mb C drive and a D drive where everything else goes. This C and D is only visible in WinPE and in Diskpart as partitions, inside the real Windows the D is visible as your C. Whenever we applied a Win 7 image to an old XP machine we would get the bootmgr is missing error and have to resort to the Win 7 disk to fix it just like you seem to have to do. This could be because of that 100mb system partition. If you have multiple PCs you can test this by booting them all into WinPE (an XP, Win 7 purchased, and Win7 built from scratch) and you are likely to see many different types or partitions if you do DISKPART, Select Disk 0, Detail disk and just compare. In my environment we always blew everything away and started from scratch when installing Win 7 in the drive options page. Finally we realized that just as you capture an image of your main OS partition you could also capture an image of the 100mb system partition and apply it down as well. So we began Sysprepping and capturing the C drive as a .WIM and also our D drive as the main OS .WIM. Then when building a new PC we simply apply both. After both images have applied if we reboot we still get the BootMgr is Missing error and we would have to resort to the installation disk. If we apply the image and then type bcdboot.exe d:\windows (or C in your case) when the PC boots it will give you the Dual Boot option. Click Enter on the first one and the OS will load as it normally does. Then click the START button and type MSCONFIG in the text box, go to the Boot tab(2nd one) and remove the 2nd entry that just says C:\ or D:\ Leave the Entry that says C(or D):\Windows (current os : Defualt OS). Then on reboot the Dual Boot option is gone and windows will boot successfully. So you might try just doing the bcdboot step after your image and see if that stops you from having to do the Repair. If it works then you can ignore all the mumbo jumbo about the 100mb system reserve. If you still have to do the start up repair then Windows may be applying that for you behind the scenes so the next time you sysprep a machine you might try capturing that as a WIM as well as your OS partition. Then when applying an image you can use DISKPART commands to create partitions and assign letters so that your machine boots perfectly after the image is applied.

    just to post this out there these are the commands I use from start to finish to apply our image. The only thing needed is a previous Sysprep and captured image of both partitions.

    boot to WinPE
    DISKPART
    select disk 0
    detail disk (not necessary but it allows me to look at it)
    clean
    create partition primary size=100
    assign letter=c
    select partition 1
    active
    format fs=ntfs label=”System Reserved” quick
    create partition primary
    assign letter=d
    select partition 2
    format fs=ntfs label=”System” quick
    exit
    E: (looking for DVD or External HD)
    dir
    F: (looking for DVD or External HD)
    dir
    E:\imagex.exe /apply F:\100MBSystemReserve.wim 1 c:
    E:\imagex.exe /apply F:\NormalWindowsImage.wim 1 c:
    bcdboot.exe d:\windows
    exit

    • David, you’re missing the point on the Win 7 BCD partition and making your life harder having to boot from a DVD to repair boot files. The “System” partition is reserved for the BCD store (for booting), the Windows Recovery Environment and BitLocker for some Windows 7 editions.

      Create the 2 partitions with DiskPart as per your post. Now restore your .wim image to the D: drive (per your post). When you are done, use bcdboot.exe to copy the default boot files from your Windows partition to the ‘System’ partition. You do NOT need to apply an image to that 100MB partition. You will also not have to deal with dual boot config.

      You run the bcdboot.exe from your **restored** D: drive to the C: drive like this:
      D:\windows\system32\bcdboot.exe D:\windows /s C:\ (can also specify “/l en-US” to set US language)

      You’re done. If performed like this, you will not have to apply 2 images, use a DVD to Repair Startup Files or edit Dual Boot configs. Or get the bootmgr is missing error :)

      • thanks. so basically I can just remove the *.wim to my C drive which will then save me from doing the MSCONFIG step as well. I will test in the AM. I already do the bcdboot to the D step within WinPE

        I don’t do a win 7 disc boot to fix the bootmgr issue. the article seemed to suggest doing that and the previous desktop admin at my job would do that to solve the issue (basically he would build Win 7 from scratch and then go back and apply the image to the D drive) He had that problem only on XP machines where the 100mb partition didn’t exist so that was his solution…do everything twice lol. I avoided having to do that once he left the company with my *.wim to the C and D drive solution but your tip may save me from having to do that step and is cleaner.

      • Correct. Remove the C .wim image as running the bcdboot command creates the files that should be in the 100mb partition. That also saves you from MSCONFIG. As long as bdcboot is run from D to C.

        You can also look into modifying the WindowsRE environment and even assigning custom Fx button presses at startup to give your users a very quick restore function (similar to Lenovo or more the modern Dell System Restore). It’s all functionality built into the WindowsRE for Win 7 & 8 and not hard to do. Awesome for business laptop users on the go.

      • Would imagex /capture /boot c: d:\image.wim “image name” /compress fast /verify eliminate the “BOOTMGR IS MISSING” problem?

      • No, it would not. The /boot flag only marks a volume image as bootable, it doesn’t actually capture the MBR section and system files. Hence the issue. And it’s available only for Windows PE images.

  6. When i was capture the image through winPE boot using a pendrive i can regonize my other external drive its says “NOT READY” any one can help me please.

  7. An impressive share! I’ve just forwarded this onto
    a co-worker who was conducting a little homework
    on this. And he in fact ordered me lunch because I
    found it for him… lol. So let me reword this….

    Thank YOU for the meal!! But yeah, thanks for spending the time to discuss this matter
    here on your website.

  8. I have been surfing online more than three hours
    today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. Personally, if all webmasters
    and bloggers made good content as you did, the
    internet will be much more useful than ever before.

  9. Well it helped me a lot to understand BCDBoot issues, my previous Windows 7 was giving me straight Boot from Single partition “C:”.

    Regards
    Abbas Jafri
    NCR Corporation.
    Dubai
    Abbas.Jafri@ncr.com

    If you want I have some automated process of doing all these time consuming Stuff.

Leave a Reply to Andrew Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: