找回密码
 加入
搜索
查看: 154|回复: 3

[网络通信] 【已解决】求助,调用文件执行时窗口闪烁

[复制链接]
发表于 2024-10-2 12:50:51 | 显示全部楼层 |阅读模式
本帖最后由 h111666b 于 2024-10-7 08:33 编辑

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $SubGui, $Width = 560, $Height = 280, $BfBtn
$SubGui = GUICreate("备份窗口", $Width, $Height, -1, -1)
;备份
$BfBtn = GUICtrlCreateButton("备份(&Y)", 262, 168, 80, 30)
GUISetState()

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $BfBtn
                        ;备份
                        Example()
        EndSwitch
WEnd

Func Example()
        RunWait(@ScriptDir & "\Imagex.exe" & " /capture " & "G:\WinPE G:\Win7.wim Win7备份 Win7说明" & " /compress fast", "", @SW_HIDE)
EndFunc   ;==>Example

;以上代码调用微软Imagex.exe备份程序,执行时窗口和备份按钮闪烁不断,特此求助。

本帖子中包含更多资源

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

×
发表于 2024-10-7 01:07:31 | 显示全部楼层
用run会不会好些
发表于 2024-10-7 03:01:16 | 显示全部楼层


还闪不闪
#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

本帖子中包含更多资源

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

×
 楼主| 发表于 2024-10-7 08:33:05 | 显示全部楼层
感谢楼上,解决了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-16 08:23 , Processed in 0.085389 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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