关于GimageX显示进度条问题
本帖最后由 liuyq 于 2010-3-8 14:53 编辑最近要做一个恢复wim的工具,希望在恢复win时显示恢复进度。下面是我改的一段国外的代码,可在恢复过程中不显示进度(原代码也无法显示进度),请高手帮忙看一下Dim $iRC, $oWIM, $oEvent
$oWIM = ObjCreate("GimageX.GimageXCtrl")
$oEvent = ObjEvent($oWIM, "ImageXEvent_")
ProgressOn("ImageX", "Please wait ...")
$oWIM.Source = "d:\1\1.wim"
$oWIM.Destination = "d:\1\test"
$oWIM.ImageIndex = 1
$oWIM.Check = TRUE
$oWIM.Verify = TRUE
$iRC = $oWIM.ApplyImage
ConsoleWrite("RC:" & @TAB & $iRC & @CRLF & "@error:" & @TAB & @error & @CRLF)
$oEvent = 0
$oWIM = 0
ProgressOff()
Func ImageXEvent_Progress($iPercent, $iSeconds)
ProgressSet($iPercent, "ETA: " & $iSeconds & " seconds")
ConsoleWrite("ETA:" & @TAB & @TAB & $iSeconds & @CRLF & "Progress:" & @TAB & $iPercent & @CRLF)
EndFunc ;==>ImageXEvent_ProgressGimageX 相关信息
http://www.autoitscript.com/gimagex/ 国外源代码#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.10.0
Author: Bj�rn Kaiser
Script Function:
Use Gimagex_com wrapper
#ce ----------------------------------------------------------------------------
#include-once
;===============================================================================
;
; Function Name: _gimagex_capture()
; Description: Captures a Folder to a .WIM-file
; Parameter(s):
; Return Value(s):On Success - Returns 1
; On Failure - Returns 0
; @error Value(s):
; Author(s):
;
;===============================================================================
Func _gimagex_capture(ByRef $oWIM, $sSource, $sDest, $sName, $sDesc = 0, $sFlags = 0, $bCheck = 0, $bVer = 0, $bBoot = 0)
;~ Local $oWIM
; Parameter Checking
;===============================================================================
If Not IsString($sSource) Then
SetError(1)
Return 0
EndIf
If Not IsString($sDest) Then
SetError(2)
Return 0
EndIf
If Not IsString($sName) Then
SetError(3)
Return 0
EndIf
;===============================================================================
;~ $oWIM = ObjCreate("GImageX.GImageXCtrl")
If IsObj($oWIM) Then
With $oWIM
.Source = $sSource
.Destination = $sDest
.ImageName = $sName
If $sDesc Then .Description = $sDesc
If $sFlags Then .Flags = $sFlags
If $bCheck Then
.Check = True
Else
.Check = False
EndIf
If $bVer Then
.Verify = True
Else
.Verify = False
EndIf
If $bBoot Then
.Bootable = True
Else
.Bootable = False
EndIf
EndWith
$oWIM.CaptureImage
Else
SetError(9)
Return 0
EndIf
;~ $oWIM = 0
Return 1
EndFunc ;==>_gimagex_capture
;===============================================================================
;
; Function Name: _gimagex_apply()
; Description: Applies a .WIM-file to a path
; Parameter(s):
; Return Value(s):On Success - Returns 1
; On Failure - Returns 0
; @error Value(s):
; Author(s):
;
;===============================================================================
Func _gimagex_apply(ByRef $oWIM, $sSource, $sDest, $iImage, $bCheck = 0, $bVer = 0)
;~ Local $oWIM
; Parameter Checking
;===============================================================================
If Not IsString($sSource) Then
SetError(1)
Return 0
EndIf
If Not IsString($sDest) Then
SetError(2)
Return 0
EndIf
If Not IsInt($iImage) Then
SetError(3)
Return 0
EndIf
;===============================================================================
;~ $oWIM = ObjCreate("GImageX.GImageXCtrl")
If IsObj($oWIM) Then
With $oWIM
.Source = $sSource
.Destination = $sDest
.Image = $iImage
If $bCheck Then
.Check = True
Else
.Check = False
EndIf
If $bVer Then
.Verify = True
Else
.Verify = False
EndIf
EndWith
$oWIM.ApplyImage
Else
SetError(9)
Return 0
EndIf
;~ $oWIM = 0
Return 1
EndFunc ;==>_gimagex_apply
;===============================================================================
;
; Function Name: _gimagex_object()
; Description: Creates a GImageX object
; Parameter(s):
; Return Value(s):On Success - Returns GImageX object
; On Failure - Returns 0
; @error Value(s):
; Author(s):
;
;===============================================================================
Func _gimagex_object()
Local $oWIM
$oWIM = ObjCreate("GImageX.GImageXCtrl")
If IsObj($oWIM) Then
Return $oWIM
Else
Return 0
EndIf
EndFunc
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.10.0
Author: Bj�rn Kaiser
Script Function:
#ce ----------------------------------------------------------------------------
Opt("MustDeclareVars", 1)
#include <gimagex_com.au3>
Dim $iRC, $oWIM, $oEvent
$oWIM = _gimagex_object()
If $oWIM Then
$oEvent = ObjEvent($oWIM, "ImageXEvent_")
ProgressOn("ImageX", "Please wait ...")
$iRC = _gimagex_capture($oWIM, "D:\projects", "D:\test.wim", "test")
ConsoleWrite("RC:" & @TAB & $iRC & @CRLF & "@error:" & @TAB & @error & @CRLF)
$oEvent = 0
$oWIM = 0
ProgressOff()
EndIf
Func ImageXEvent_Progress($iPercent, $iSeconds)
ProgressSet($iPercent, "ETA: " & $iSeconds & " seconds")
ConsoleWrite("ETA:" & @TAB & @TAB & $iSeconds & @CRLF & "Progress:" & @TAB & $iPercent & @CRLF)
EndFunc ;==>ImageXEvent_Progress 找出了个问题,不是不显示,而是没有实时显示,所有信息都在镜像恢复完成后显示,由于太快无法看到,我在ProgressSet($iPercent, "ETA: " & $iSeconds & " seconds")后加了个Sleep(1000),可以看到在镜像恢复完成后显示进度条。现在的问题如何让他实时显示。
还有个问题进度条走了两遍,不知道为什么。
页:
[1]