demo

最怕万一见温柔發表於2024-07-01
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

; 建立GUI
$Form1 = GUICreate("AutoIt GUI Example", 400, 200)
$Label1 = GUICtrlCreateLabel("選擇目標資料夾:", 10, 10, 120, 20)
$Input1 = GUICtrlCreateInput("", 140, 10, 200, 20)
$Browse1 = GUICtrlCreateButton("瀏覽...", 350, 10, 40, 20)

$Label2 = GUICtrlCreateLabel("建立新資料夾:", 10, 50, 120, 20)
$Input2 = GUICtrlCreateInput("", 140, 50, 200, 20)
$Browse2 = GUICtrlCreateButton("瀏覽...", 350, 50, 40, 20)

$StartButton = GUICtrlCreateButton("開始", 150, 100, 100, 30)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit`

        Case $Browse1
            $source_folder = FileSelectFolder("選擇目標資料夾", "")
            If Not @error Then
                GUICtrlSetData($Input1, $source_folder)
            EndIf

        Case $Browse2
            $destination_folder = FileSelectFolder("選擇新資料夾位置", "")
            If Not @error Then
                $new_folder = InputBox("建立新資料夾", "請輸入新資料夾名稱", "")
                If $new_folder <> "" Then
                    $destination_folder &= "\" & $new_folder
                    DirCreate($destination_folder)
                    GUICtrlSetData($Input2, $destination_folder)
                EndIf
            EndIf

        Case $StartButton
            $source_folder = GUICtrlRead($Input1)
            $destination_folder = GUICtrlRead($Input2)
            If $source_folder <> "" And $destination_folder <> "" Then
                ; 複製EXE和DLL檔案
                FileCopy($source_folder & "\*.exe", $destination_folder)
                FileCopy($source_folder & "\*.dll", $destination_folder)

                ; 開啟目標程式並自動化操作
                Run("C:\path\to\target_program.exe")
                WinWaitActive("目標程式視窗標題")

                ; 模擬操作,具體操作視實際應用而定
                ; 例如:選擇檔案、勾選選項、儲存
                Send("!f") ; 開啟檔案選單
                Send("a")  ; 選擇新增檔案
                WinWaitActive("開啟")
                Send($destination_folder & "\*.exe{ENTER}")
                Send($destination_folder & "\*.dll{ENTER}")
                ControlClick("目標程式視窗標題", "", "核取方塊ID")
                Send("!f") ; 開啟檔案選單
                Send("s")  ; 儲存

                Sleep(5000) ; 等待儲存完成
                WinClose("目標程式視窗標題")
                WinWaitClose("目標程式視窗標題")

                MsgBox($MB_OK, "完成", "操作已完成")
            Else
                MsgBox($MB_OK, "錯誤", "請選擇目標資料夾和建立新資料夾")
            EndIf
    EndSwitch
WEnd