Global $hProgress, $hLabel, $hTitle = '进度条'
; 创建GUI窗口
$hGUI = GUICreate($hTitle, 300, 100)
$hProgress = GUICtrlCreateProgress(10, 30, 280, 20)
$hLabel = GUICtrlCreateLabel("100%", 140, 60, 100)
GUISetState(@SW_SHOW)
; 执行解压
RunCmd("wimlib-imagex apply win7.wim 1 文件夹")
; 关闭GUI窗口
Sleep(3000)
GUIDelete($hGUI)
Func RunCmd($sCommand)
Local $sOutput, $aSRE
Local $iPID = Run($sCommand, @ScriptDir, @SW_HIDE, 6)
While 1
If ProcessExists($iPID) = 0 Then
$hTitle = 'Done applying WIM image.'
WinSetTitle($hGUI, '', $hTitle)
GUICtrlSetData($hProgress, 100)
GUICtrlSetData($hLabel, 100 & "%")
ExitLoop
EndIf
$sOutput = StdoutRead($iPID, False, True)
$sOutput = BinaryToString($sOutput, 4)
If StringRegExp($sOutput, 'Applying|done', 0) Then
;ConsoleWrite($sOutput & @CRLF)
$aSRE = StringRegExp($sOutput, 'Creating.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Creating files' Then
$hTitle = 'Creating files'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE[0])
GUICtrlSetData($hLabel, $aSRE[0] & "%")
EndIf
$aSRE = StringRegExp($sOutput, 'Extracting.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Extracting file data' Then
$hTitle = 'Extracting file data'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE[0])
GUICtrlSetData($hLabel, $aSRE[0] & "%")
EndIf
$aSRE = StringRegExp($sOutput, 'Applying.+?\((\d+?)\%\).+?$', 1)
If Not @error Then
If $hTitle <> 'Applying metadata to files' Then
$hTitle = 'Applying metadata to files'
WinSetTitle($hGUI, '', $hTitle)
EndIf
GUICtrlSetData($hProgress, $aSRE[0])
GUICtrlSetData($hLabel, $aSRE[0] & "%")
EndIf
EndIf
Sleep(100)
WEnd
EndFunc ;==>RunCmd