Jump to content

Stdout + Imagex.exe


 Share

Recommended Posts

I am trying to use imagex and pipe it's output to an edit box, but at runtime the GUI freezes and the edit control is only updated after the process has ended

The command that I am using is as follows: (Note you have to the WAIK installed AND have a WIM file mounted in C:\Winpe for this to work!)

#include <GUIConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 460, 249, 307, 321)
$Edit1 = GUICtrlCreateEdit("", 40, 56, 393, 121)
GUICtrlSetData(-1, "AEdit1")
$executebtn = GUICtrlCreateButton("execute", 352, 192, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

If $nMsg = $executebtn Then _execute()

Func _execute()
    
$i_Pid = Run('C:\Program Files\Windows AIK\Tools\x86\Imagex.exe /boot /capture C:\Winpe\mount WinpeCustom.wim "Windows PE Custom Build" ', @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 

    $test = ''
    While 1
        $data = StdoutRead($i_Pid)
        If @error = -1 Then ExitLoop
        GUICtrlSetData($Edit1, $data,1)
        $test &= $data
    WEnd
EndFunc

This is the result that should appear at runtime in the edit control, but only does so after the process has ended

CODE
ImageX Tool for Windows

Copyright © Microsoft Corp. 1981-2005. All rights reserved.

Files/folders excluded from image capture by default:

\WINDOWS\CSC

\RECYCLER

\System Volume Information

\pagefile.sys

\hiberfil.sys

\$ntfs.log

Successfully imaged C:\Winpe\mount

Anyone got any ideas?

Cheers

Link to comment
Share on other sites

Once your Gui is created and shown, then it will go into the message loop. The only Case statement used to do anything will Exit the script :whistle:. So not sure how you even get any stdout data. Add a Case statement to read the $executebtn handle within the message loop to call your UDF. The $test variable seems like it is doing nothing also.

:lmao:

Link to comment
Share on other sites

Opps, that was the wrong code posted initially..

Here is the amended code...sorry for the error

#include <GUIConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 460, 249, 307, 321)
$Edit1 = GUICtrlCreateEdit("", 40, 56, 393, 121)
$executebtn = GUICtrlCreateButton("execute", 352, 192, 81, 25, 0)
$exitbtn = GUICtrlCreateButton("exit", 250, 192, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE Or $exitbtn
    Exit
    EndSwitch
    If $nMsg = $executebtn Then _execute()
WEnd



Func _execute()
    
    
    $i_Pid = Run('C:\Program Files\Windows AIK\Tools\x86\Imagex.exe /boot /capture C:\Winpe\mount WinpeCustom.wim "Windows PE Custom Build" ', @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    $data = ''
    While 1
        $data = StdoutRead($i_Pid)
        If @error = -1 Then ExitLoop
        GUICtrlSetData($Edit1, $data, 1)
        ExitLoop
    WEnd
EndFunc  ;==>_execute
Link to comment
Share on other sites

Without testing, I have tidied up the code to perhaps a workable state. You may need to double check my quoting of the switches as I am guessing the break of spacing between each switch used.

#include <GUIConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 460, 249, 307, 321)
$Edit1 = GUICtrlCreateEdit("", 40, 56, 393, 121)
$executebtn = GUICtrlCreateButton("execute", 352, 192, 81, 25, 0)
$exitbtn = GUICtrlCreateButton("exit", 250, 192, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exitbtn
            Exit
        Case $executebtn
            _execute()
    EndSwitch
WEnd

Exit

Func _execute()
    Local $data, $i_Pid, $switches = '/boot /capture "C:\Winpe\mount" "WinpeCustom.wim" "Windows PE Custom Build"'
    $i_Pid = Run('"' & @ProgramFilesDir & '\Windows AIK\Tools\x86\Imagex.exe" ' & $switches, @WorkingDir, @SW_HIDE, $STDOUT_CHILD)
    While 1
        $data = StdoutRead($i_Pid)
        If @error Then
            Return
        EndIf
        GUICtrlSetData($Edit1, $data, 1)
    WEnd
EndFunc
Link to comment
Share on other sites

Without testing, I have tidied up the code to perhaps a workable state. You may need to double check my quoting of the switches as I am guessing the break of spacing between each switch used.

#include <GUIConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 460, 249, 307, 321)
$Edit1 = GUICtrlCreateEdit("", 40, 56, 393, 121)
$executebtn = GUICtrlCreateButton("execute", 352, 192, 81, 25, 0)
$exitbtn = GUICtrlCreateButton("exit", 250, 192, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exitbtn
            Exit
        Case $executebtn
            _execute()
    EndSwitch
WEnd

Exit

Func _execute()
    Local $data, $i_Pid, $switches = '/boot /capture "C:\Winpe\mount" "WinpeCustom.wim" "Windows PE Custom Build"'
    $i_Pid = Run('"' & @ProgramFilesDir & '\Windows AIK\Tools\x86\Imagex.exe" ' & $switches, @WorkingDir, @SW_HIDE, $STDOUT_CHILD)
    While 1
        $data = StdoutRead($i_Pid)
        If @error Then
            Return
        EndIf
        GUICtrlSetData($Edit1, $data, 1)
    WEnd
EndFunc
Hi MHZ

Your code as far as the switches and double quotes go all worked, but the data is still only piped back to the edit control after the "Imagex.exe" process ends.

Not sure you know of what Imagex does and is, but it captures a volume of a hard drive into a *.wim file that is used in Vista deployments. This in turn does use quite a lot of CPU, (about 40%) on my PC, so I am wondering if this is the cause as there is a lot of data being captured, but only a small amount of text being sent back to the screen, if you know what I mean?

Puzzling

Link to comment
Share on other sites

Hi MHZ

Your code as far as the switches and double quotes go all worked, but the data is still only piped back to the edit control after the "Imagex.exe" process ends.

Puzzling

Try using RTConsole.exe LINK

This web page explain you the reason why the data piped back to the edit control after the "Imagex.exe" process ends.

The only change you need to apply is to _execute() UDF.

$i_Pid = Run('RTConsle.exe ' & '"' & @ProgramFilesDir & '\Windows AIK\Tools\x86\Imagex.exe" ' & $switches, @WorkingDir, @SW_HIDE, $STDOUT_CHILD)

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I have the full WAIK. I have not used imagex with stdout yet to know of it's output.

I would try sending a CRLF 1st using StdInWrite() as VBScript normally does. I have found success in the past with using StdInWrite() to open the stdout pipe fully.

#include <GUIConstants.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 460, 249, 307, 321)
$Edit1 = GUICtrlCreateEdit("", 40, 56, 393, 121)
$executebtn = GUICtrlCreateButton("execute", 352, 192, 81, 25, 0)
$exitbtn = GUICtrlCreateButton("exit", 250, 192, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exitbtn
            Exit
        Case $executebtn
            _execute()
    EndSwitch
WEnd

Exit

Func _execute()
    Local $data, $i_Pid, $switches = '/boot /capture "C:\Winpe\mount" "WinpeCustom.wim" "Windows PE Custom Build"'
    $i_Pid = Run('"' & @ProgramFilesDir & '\Windows AIK\Tools\x86\Imagex.exe" ' & $switches, @WorkingDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    StdInWrite($i_Pid, @CRLF)
    While 1
        $data = StdoutRead($i_Pid)
        If @error Then
            Return
        EndIf
        GUICtrlSetData($Edit1, $data, 1)
    WEnd
EndFunc
Link to comment
Share on other sites

Danny35D, MHZ

Thanks for the responses guys..

I tried both options, Danny35D's RTConsole method did indeed give me a stdout to the edit control, but I got a GPF using so it seems that the output that imagex must be using a huge buffer size

MHZ, The option you suggested unfortunately didn't work for meas before

Back to the drawing board..

Hmmmm

Edited by lyledg
Link to comment
Share on other sites

Danny35D, MHZ

Thanks for the responses guys..

I tried both options, Danny35D's RTConsole method did indeed give me a stdout to the edit control, but I got a GPF using so it seems that the output that imagex must be using a huge buffer size...

The edit control will only hold so much so if the amount of data being piped back is too great, then by my testing with using an edit control, is that the script will stall once the limit is reached. Since you have not mentioned of the script stalling, then you are still within the limit.

I have found that StdOutRead() can keep emptying the buffer so whatever is blocking the flow would be elsewhere by my best guess. Try using FileWrite(), instead of GuiCtrlSetData() to see if you do get the full amount of stdout. That test may help isolate where the issue is in removing Gui functions from the task.

Link to comment
Share on other sites

Ok, thanks for the advice

basically, the script does stall until all the data is piped back into the edit control. I think I might have to resort to piping it out to a text file and reading that data back into the edit control..

I think Imagex.exe is just too big for the amount of data the Stdoutread function can handle

Forgot to add, I am increasing the buffer size of the edit control to this

$EditBufSize = 281474976710656, $EM_LIMITTEXT = 0x00c5

GUICtrlRecvMsg($EDIT, $EM_LIMITTEXT, $EditBufSize, 0)
Edited by lyledg
Link to comment
Share on other sites

I think Imagex.exe is just too big for the amount of data the Stdoutread function can handle

Or filter out information and only send back to the edit control of what is of interest so you keep within the edit controls character limit.
Link to comment
Share on other sites

That is a good idea, but the frustrating thing is the amount of data is minimal

This is the complete result after the imagex.exe process has ended

CODE
ImageX Tool for Windows

Copyright © Microsoft Corp. 1981-2005. All rights reserved.

Files/folders excluded from image capture by default:

\WINDOWS\CSC

\RECYCLER

\System Volume Information

\pagefile.sys

\hiberfil.sys

\$ntfs.log

Successfully imaged C:\Winpe\mount

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...