找回密码
 加入
搜索
查看: 195|回复: 14

[AU3基础] [已解决]请帮忙修改一下代码显示百分比谢谢

[复制链接]
发表于 2025-4-22 23:26:45 | 显示全部楼层 |阅读模式
本帖最后由 令狐大虾 于 2025-4-27 19:38 编辑
<div class="blockcode"><blockquote>#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

; 创建GUI窗口
Local $hGUI = GUICreate("WIM释放工具", 400, 150)
Local $idProgress = GUICtrlCreateProgress(20, 20, 360, 30)
Local $idLabel = GUICtrlCreateLabel("准备中...", 20, 70, 360, 20)
GUISetState(@SW_SHOW)

; 定义wimlib命令参数
Local $sWimFile = "64w7.wim"    ; WIM文件路径
Local $sTargetDir = "D:\Extracted"            ; 释放目标目录
Local $sWimlibPath = @ScriptDir & "\wimlib-imagex.exe" ; 工具路径

; 启动命令行进程(隐藏窗口)
Local $iPID = Run($sWimlibPath & ' apply "' & $sWimFile & '" 1 "' & $sTargetDir & '"', "", @SW_HIDE)

While 1
    ; 读取实时输出
    Local $sOutput = StdoutRead($iPID)
    If @error Then ExitLoop

    ; 解析进度百分比(示例输出行:"Progress: 50.00%")
    If StringRegExp($sOutput, "Progress:\s*(\d+\.\d+)%") Then
        Local $aMatches = StringRegExp($sOutput, "(\d+\.\d+)", 1)
        If Not @error Then
            GUICtrlSetData($idProgress, $aMatches[0])
            GUICtrlSetData($idLabel, "进度: " & $aMatches[0] & "%")
        EndIf
    EndIf
    Sleep(100)
WEnd

; 检查执行结果
If ProcessWaitClose($iPID, 0) = 0 Then
        MsgBox(64, "成功", "WIM文件已成功释放")
EndIf
进度条不出现0%到100%提示



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2025-4-22 23:49:08 | 显示全部楼层
$iPID = Run($sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 这里的格式就不对,你改成$iPID = Run(@ComSpec & " /c " & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
 楼主| 发表于 7 天前 | 显示全部楼层
zhaoceshi 发表于 2025-4-22 23:49
$iPID = Run($sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 这里的格式就不对,你改成$iPID =  ...

改成这样也没用,不会出现进度条。而且运行时候一闪而过
发表于 6 天前 | 显示全部楼层
发表于 5 天前 | 显示全部楼层
本帖最后由 zhaoceshi 于 2025-4-25 21:06 编辑
; 创建GUI窗口
Local $hGUI = GUICreate("WIM释放工具", 400, 150)
Local $idProgress = GUICtrlCreateProgress(20, 20, 360, 30)
Local $idLabel = GUICtrlCreateLabel("准备中...", 20, 70, 360, 20)
GUISetState(@SW_SHOW)

; 定义wimlib命令参数
Local $sWimFile = "64w7.wim" ; WIM文件路径
Local $sTargetDir = "D:\Extracted" ; 释放目标目录
Local $sWimlibPath = @ScriptDir & "\wimlib-imagex.exe" ; 工具路径

; 启动命令行进程(隐藏窗口)
Local $iPID = Run(@ComSpec & " /c " & $sWimlibPath & ' apply "' & $sWimFile & '" 1 "' & $sTargetDir & '"', "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
Local $sOutput = ""

While 1
        ; 读取实时输出
        Local $sOutput = StdoutRead($iPID)
        If @error Then ExitLoop
        Sleep(100)
        ConsoleWriteError($sOutput & @CRLF)
        ; 解析进度百分比(示例输出行:"Progress: 50.00%")
        Local $aMatches = StringRegExp($sOutput, "\((\d+)%\)", 1)
        If Not @error Then
                GUICtrlSetData($idProgress, $aMatches[0])
                GUICtrlSetData($idLabel, "进度: " & $aMatches[0] & "%")
        EndIf


WEnd
; 检查执行结果
If ProcessWaitClose($iPID) = 0 Then
        Exit (MsgBox(64, "成功", "WIM文件已成功释放"))
EndIf

修正了,你再试试




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 5 天前 | 显示全部楼层
zhaoceshi 发表于 2025-4-25 20:33
验证了,可以正常运行

进度条和百分比都不能动啊
发表于 5 天前 | 显示全部楼层
令狐大虾 发表于 2025-4-25 20:41
进度条和百分比都不能动啊

再看5楼
 楼主| 发表于 4 天前 | 显示全部楼层
本帖最后由 令狐大虾 于 2025-4-26 14:37 编辑

编译失败呢。用的是AutoIt v3.3.16.1。如何才能成功编译呢
发表于 4 天前 | 显示全部楼层
令狐大虾 发表于 2025-4-26 14:20
编译失败呢。用的是AutoIt v3.3.16.1。如何才能成功编译呢

你的代码编译前难道不先运行脚本文件调试的吗?
一看就至少缺少头文件吧

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
 楼主| 发表于 4 天前 | 显示全部楼层
本帖最后由 令狐大虾 于 2025-4-26 18:35 编辑
afan 发表于 2025-4-26 17:50
你的代码编译前难道不先运行脚本文件调试的吗?
一看就至少缺少头文件吧

加上也不行,不知是啥原因。用的是https://www.autoitx.com/forum.ph ... mp;highlight=Autoit
版本
 楼主| 发表于 3 天前 | 显示全部楼层
本帖最后由 令狐大虾 于 2025-4-27 10:51 编辑
zhaoceshi 发表于 2025-4-25 20:33
修正了,你再试试
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

; 创建GUI窗口
Local $hGUI = GUICreate("WIM释放工具", 400, 150)
Local $idProgress = GUICtrlCreateProgress(20, 20, 360, 30)
Local $idLabel = GUICtrlCreateLabel("准备中...", 20, 70, 360, 20)
GUISetState(@SW_SHOW)

; 定义wimlib命令参数
Local $sWimFile = "64w7.wim" ; WIM文件路径
Local $sTargetDir = "D:\Extracted" ; 释放目标目录
Local $sWimlibPath = @ScriptDir & "\wimlib-imagex.exe" ; 工具路径

; 启动命令行进程(隐藏窗口)
Local $iPID = Run(@ComSpec & " /c " & $sWimlibPath & ' apply "' & $sWimFile & '" 1 "' & $sTargetDir & '"', "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
Local $sOutput = ""

While 1
        ; 读取实时输出
        Local $sOutput = StdoutRead($iPID)
        If @error Then ExitLoop
        Sleep(100)
        ConsoleWriteError($sOutput & @CRLF)
        ; 解析进度百分比(示例输出行:"Progress: 50.00%")
        Local $aMatches = StringRegExp($sOutput, "\((\d+)%\)", 1)
        If Not @error Then
                GUICtrlSetData($idProgress, $aMatches[0])
                GUICtrlSetData($idLabel, "进度: " & $aMatches[0] & "%")
        EndIf


WEnd
; 检查执行结果
If ProcessWaitClose($iPID) = 0 Then
        Exit (MsgBox(64, "成功", "WIM文件已成功释放"))
EndIf


运行出错啊。是不是和wimlib-imagex版本有关呢。我发现Local $iPID = Run(@ComSpec & " /c " & $sWimlibPath & ' apply "' & $sWimFile & '" 1 "' & $sTargetDir & '"', "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))加了BitOR($STDERR_CHILD, $STDOUT_CHILD))就会运行出错,是不是和安装的AU3版本有关?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 3 天前 | 显示全部楼层
zhaoceshi 发表于 2025-4-25 20:33
修正了,你再试试

我看你的图片里面上面还有别的代码吧?
发表于 3 天前 | 显示全部楼层
都告诉你编译前要先运行脚本,看看是否正常,在 SciTE 里面控制台信息会很清楚。还一意孤行的直接编译,然后发个exe文件的错误提示,毛用?

#include <AutoItConstants.au3>
 楼主| 发表于 3 天前 | 显示全部楼层
afan 发表于 2025-4-27 13:52
都告诉你编译前要先运行脚本,看看是否正常,在 SciTE 里面控制台信息会很清楚。还一意孤行的直接编译,然 ...

谢谢,成功了。
 楼主| 发表于 昨天 02:09 | 显示全部楼层
zhaoceshi 发表于 2025-4-25 20:33
修正了,你再试试

请教将wimlib-imagex更改为dism命令释放进度条并不会滚动如何修改代码呢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2025-4-30 15:08 , Processed in 0.112372 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表