Quick and Dirty ImageX

Update 8/26/08: Forgot about the WinPE 2.0 uberbug with diskpart.  See this article here.  To fix this, place the following in uberbug.reg and then add that to the menu

Windows Registry Editor Version 5.00


Here’s a quick and dirty overview of how to replace Norton Ghost with ImageX. ImageX captures information about the file system, but nothing of disk structures (master boot record, sectors, etc). Therefore, in using ImageX, we need to include writing out the boot sector with bootsect.exe. Since ImageX is command line driven, the first order of business is finding a GUI wrapper. I found such a wrapper called GImageX. GImageX interacts directly with wimgapi.dll, therefore, some support files from Microsoft WAIK will be needed. Specifically, that includes: imagex.exe, intlcfg.exe, wimgapi.dll, wimfltr.inf, and wimfiltr.sys.

I threw all of the files, including the WIMs I captured, on a network share with these support files (don’t forget bootsect.exe!). I then wrote a simple batch file:

@echo off
regedit /s uberbug.reg
echo Microsoft ImageX Menu by Adam Leinss
echo ————————————–
echo 2. Prep Boot Sector for Windows XP OS
echo 3. Prep Boot Sector for Windows Vista OS
echo 4. Run GImageX
echo 5. Exit
Set /P sel=Make your choice:
For %%a In (1, 2, 3, 4, 5) Do if “%sel%”==”%%a” Goto SELECT_%%a
echo Invalid selection. Valid values are 1 thru 5. Press Enter To continue
Goto TOP
mbrwiz /disk=0 /part=* /del /confirm
diskpart -s diskprep.s
Goto TOP
bootsect /nt52 sys
Goto TOP
bootsect /nt60 sys
Goto TOP
Goto TOP
Goto :EOF

The diskprep script I use:

select disk 0
create partition primary
format quick
assign letter=C

This gets the disk nice and clean for us to use. You actually have to use MBRWiz to do the initial wipe, as “diskpart clean” only wipes one partition (versus diskpart clean all which takes forever). This is never an issue with Ghost, as it writes out the file system sector-by-sector.

After cleaning the disk, you can pick either #2 or #3 to prep the boot sector depending on what OS you are going to deploy.

Finally, we run GImageX, click the Apply tab and pick the Source/Destination. Now you have an imaged PC, just like with Ghost!

I used the WinPE 2.0 install media from SCCM 2007 to boot the PC and connect to the network share, but you can use any favor of WinPE you want (BartPE, WAIK PE, etc).  I found decent WinPE 2.0 (Vista based) setup instructions here.

Update (9/9/08): If you use WinPE 1.x: it has an older version of diskpart that does not have the format command built-in.  So you can either update the version of diskpart on the WinPE 1.x disc or re-write the script so the the format command in diskprep.s is taken out, then you can use “format C: /fs:ntfs /quick” on another line.  The WinPE 1.x diskpart also does not handle USB flash drives correctly and you cannot simply copy diskpart from WinPE 1.x to WinPE 2.0.  Therefore, I strongly urge you to use WinPE 2.0 for dealing with images.

Sample VBScript code below to map network drivers if you have multiple locations on different subnets.  Note that if you just use straight up net use commands, you might run into timing issues since WinPE will not wait until executing the next line of code.  Using the run object with the 1 option will prevent WinPE from continuing on until the drive is mapped.

Set objShell = WScript.CreateObject("WScript.Shell")
Set colItems = GetObject("winmgmts://.").ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For each objItem In colItems
If Not IsNull(objItem.IPAddress) Then
strIP = "IPAddress: " & objItem.IPAddress(i)
End If
If InStr(strIP,"10.3.") Then
objShell.run("net use * \server3osd /user:yourdomainsrvacct secretpwd"),1,true
ElseIf InStr(strIP,"10.2.") Then
objShell.run("net use * \server2osd /user:yourdomainsrvacct secretpwd"),1,true
ElseIf InStr(strIP,"10.1.") Then
objShell.run("net use * \server1osdsccm2007images /user:yourdomainsrvacct secretpwd"),1,true
End If

Update (8/20/11): Upon designing a simplified GimageX setup for another company, I discovered for Windows 7 you can use BCDBOOT to fix boot sector/BCD issues after wiping a disk and using the raw imagex binaries to throw down an image.  Copy the x86 version of bcdboot.exe from an existing Windows 7 installation (to match your version of WinPE which is likely x86) to your network share, then issue bcdboot C:windows after the image is laid down and the BCD will be fixed.  You can place this command after gimagex.exe in the menu so you don’t have to run it as a menu option if the only operating system you are imaging is Windows 7.

Though I didn’t use it, you can also use the Microsoft Script Encoder to obfuscate your VBS script code to keep out the nosy Nellies.  

– Soli Deo Gloria

4 Replies to “Quick and Dirty ImageX”

  1. Adam, I’m just curious have you been able to mount an existing image using ImageX or GImageX for that matter under WinPE 2.0?

    If you haven’t already I’d greatly appreciate if you try. I think you have all the required files (listed in your post), but I think one of those needs to somehow be added as a driver.

    I’m asking since I’ve tried multiple times, but never had the ability to mount an image under WinPE 2.0.

    Thanks in advance.

  2. Actually, I have. I just built a WinPE 2.0 disc from the instructions at http://www.svrops.com/svrops/articles/winvistape2.htm this morning. I then editted the startnet.cmd file in C:windowssystem to automatically map a network drive to my Ghost server and run the image menu.

    I zipped up the files I am using and placed them here for you: http://www.leinss.com/files/winpe_imagex.zip. These files are from SCCM 2007 which uses a different WAIK then what is Microsoft is hosting now, but I don’t think it should matter.

  3. Hmm, I actually used the exact same tutorial to build my WinPE 2.0.
    I tried to mount a .wim using the files you so kindly put up, but it still fails.

    The command I’m using is simple (and works just fine on any machine I have WAIK installed, but not under any WinPE 2.0 I’ve build):
    imagex.exe /mountrw c:/winpe.wim 1 c:/testmount

    The error I get each and everytime is:
    Error mounting image (RW):
    The system cannot find the file specified

    I know I saw a thread on http://www.msfn.com/board a while back, where someone said they couldn’t mount it under WinPE 2.0 and this has been confirmed by multiple people (I naturally can’t find that thread now).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.