I've searched the forums and researched different sources about using or controlling Imagex.exe with Autoit. One of the drawbacks I and many others have had is getting callback or feedback information from it in order to properly display progress (ie. ProgressBar) in a script. Especially if you are trying to apply an image to a drive because of the multi-threading issue. Sure, we could run Imagex and let the user see the text progress from an unhidden command window, but where's the fun in that?
Below is some code I've been tinkering with that might be a solution:
ProgressOn("Progress Meter", "Increments every second", "0 percent")
$RunImagex = Run("imagex.exe /Apply c:\temp\winpe.wim 1 c:\temp2", "c:\temp")
$CurDirSize = DirGetSize("c:\temp2")
$Size = (($CurDirSize/$NeededSpace)*100)
$Perc = (Round ($Size, 0))
ProgressSet ($Perc, $Perc & " percent")
If $CurDirSize >= $NeededSpace Then
If ProcessExists ("Imagex.exe") = 0 Then ExitLoop
msgbox(0,"", "Return code: " & $RunImagex & @CRLF & "Current Folder Size: " & $CurDirSize & @CRLF & "Size That Was Needed: " & $NeededSpace)
Please excuse my sloppy code as this is just for demonstration purposes.
I have two folders on the root of C: named TEMP and TEMP2 (yeah, I know, real imaginative). This script resides in TEMP along with the WIM file I'll be using and TEMP2 is empty. Also, Imagex.exe is in my path and Wimfltr.sys is applied as I am running XP. (Not that I need it for this demonstration). The WIM file is simply a PE 2.0 image that I extracted from the MS WAIK for testing purposes. As it stands now this script works very effectively and gives me a nice clean progress bar. My only drawback is $NeededSpace is a given in the beginning. This does not trouble me too much because if you run Imagex against your WIM file with the /INFO switch you can glean through the XML output the TotalBytes that the uncompressed image will require.
In this example I am polling DirGetSize every second to compare the current folder size of TEMP2 against $NeededSpace. More or less when they are equal then my progress bar should read 100%. If you were applying the image to a drive letter you could use DriveSpaceFree and DriveSpaceTotal to get the same results I would imagine (more testing to come). In case the operation errors out or Imagex blows up I use ProcessExists to see if Imagex.exe is still running and if it isn't then I exit the loop.
So, basically I have two questions for you fine folk:
1. Has anyone else already tried this approach? If so, would you be so kind as to point me in the right direction where I might find examples?
2. Does anyone know the exit or return codes from Imagex.exe? You'll notice if you try the above script that you'll get differing results for $RunImagex each time you successfully run it. Knowing what Imagex returns would be a great help in knowing if the apply operation was successful or not.
Of course, the only drawback to this method is that your target folder or drive must be empty when you start. What I want to use this for is a template script that I can burn on a PE 2.0 DVD with any WIM file I choose and be able to get the same clean results. One use for this would be, if you were a system builder, you could create a clean image of an install, place it on a DVD with this script and give the user an instant recovery disk.
At any rate, any help I could get would be appreciated. Thanks.
Edit: Disregard the return code from $RunImagex. I am such a noob that I assumed since RunWait returns exit codes that Run does as well. Doh! RTFM!
Edited by Catdaddy, 02 July 2008 - 05:14 PM.