#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <WinAPI.au3>
#include <NamedPipes.au3>
Opt('GUIOnEventMode', 1)
Global $hProcess, $SubGui, $Width = 560, $Height = 280, $BfBtn, $hEdit
$SubGui = GUICreate("备份窗口", $Width, $Height, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
$BfBtn = GUICtrlCreateButton("备份(&Y)", 475, 50, 80, 30)
GUICtrlSetOnEvent(-1, 'Backup')
$hEdit = GUICtrlCreateEdit('', 10, 10, 460, 260, 0x00200000)
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func Backup()
CaptureConsole('Imagex.exe /capture E:\IDA_Pro E:\Win7.wim Win7备份 Win7说明 /compress fast', 'UpdateEdit')
EndFunc ;==>Example
Func UpdateEdit($sData)
_GUICtrlEdit_AppendText($hEdit, $sData)
GUICtrlSendMsg($hEdit, 0x00B7, 0, 0)
EndFunc
Func _Exit()
If _WinAPI_GetExitCodeProcess($hProcess) = 259 Then _WinAPI_TerminateProcess($hProcess, 0)
_WinAPI_CloseHandle($hProcess)
Exit
EndFunc
Func CaptureConsole($sCommand, $callback)
Local $buffer, $hRead, $hWrite, $bytesRead, $SzBuffer = DllStructCreate('char SzBuffer[1024]')
Local $tagSTARTUPINFO = DllStructCreate("int Size;ptr Reserved1;ptr Desktop;ptr Title;int X;int Y;int XSize;int YSize;int XCountChars;" & _
"int YCountChars;int FillAttribute;int Flags;short ShowWindow;short Reserved2;ptr Reserved3;int StdInput;" & _
"int StdOutput;int StdError")
Local $tagPROCESS_INFORMATION = DllStructCreate('hwnd hProcess;hwnd hThread;int ProcessID;int ThreadID')
Local $tagSECURITY_ATTRIBUTES = DllStructCreate('int Length;ptr Descriptor;int InheritHandle')
DllStructSetData($tagSECURITY_ATTRIBUTES, 'Length', DllStructGetSize($tagSECURITY_ATTRIBUTES))
DllStructSetData($tagSECURITY_ATTRIBUTES, 'InheritHandle', True)
DllStructSetData($tagSECURITY_ATTRIBUTES, 'Descriptor', Null)
If _NamedPipes_CreatePipe($hRead, $hWrite,DllStructGetPtr($tagSECURITY_ATTRIBUTES)) <> False Then
DllStructSetData($tagSTARTUPINFO, 'Size', DllStructGetSize($tagSTARTUPINFO))
DllStructSetData($tagSTARTUPINFO, 'StdOutput', $hWrite)
DllStructSetData($tagSTARTUPINFO, 'StdError', $hWrite)
DllStructSetData($tagSTARTUPINFO, 'Flags', '0x101')
DllStructSetData($tagSTARTUPINFO, 'ShowWindow', @SW_HIDE)
If _WinAPI_CreateProcess('', $sCommand, Null, Null, True, 0, Null, Null, DllStructGetPtr($tagSTARTUPINFO), DllStructGetPtr($tagPROCESS_INFORMATION)) <> False Then
$hProcess = DllStructGetData($tagPROCESS_INFORMATION, 'hProcess')
_WinAPI_CloseHandle($hWrite)
While 1
If _WinAPI_GetExitCodeProcess($hProcess) <> 259 Then ExitLoop
Local $aInfo = _NamedPipes_PeekNamedPipe($hRead)
If @error Then
ConsoleWrite('PeekNamedPipe error: ' & @error & @CRLF)
ExitLoop
EndIf
If $aInfo[2] > 0 Then
_WinAPI_ZeroMemory(DllStructGetPtr($SzBuffer), DllStructGetSize($szBuffer))
If _WinAPI_ReadFile($hRead, DllStructGetPtr($SzBuffer), DllStructGetSize($SzBuffer), $bytesRead) = False Then
ConsoleWrite(StringFormat('ReadFile error:%d\r\nReadFile error msg:%s\r\n', _WinAPI_GetLastError(), _WinAPI_GetLastErrorMessage()))
ExitLoop
Else
$buffer &= DllStructGetData($SzBuffer, 1)
Call($callback, $buffer)
$buffer = ''
EndIf
EndIf
WEnd
EndIf
_WinAPI_CloseHandle($hRead)
_WinAPI_CloseHandle(DllStructGetData($tagPROCESS_INFORMATION, 'hThread'))
EndIf
EndFunc ;==>CaptureConsole