找回密码
 加入
搜索
查看: 126|回复: 9

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

[复制链接]
发表于 4 天前 | 显示全部楼层 |阅读模式
本帖最后由 令狐大虾 于 2025-4-24 00:01 编辑
<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%提示



本帖子中包含更多资源

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

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

改成这样也没用,不会出现进度条。而且运行时候一闪而过
发表于 前天 09:11 | 显示全部楼层
发表于 昨天 20:33 | 显示全部楼层
本帖最后由 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

修正了,你再试试




本帖子中包含更多资源

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

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

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

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

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

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

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

加上也不行,不知是啥原因。用的是https://www.autoitx.com/forum.ph ... mp;highlight=Autoit
版本
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2025-4-26 19:10 , Processed in 0.103429 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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