使用AutoHotkey自动化WinReducer时遇到麻烦

时间:2018-09-03 19:35:51

标签: autohotkey

我正在尝试使用AutoHotkey通过WinReducer:https://www.winreducer.net/winreducer-ex-100.html将某些自定义项自动应用于Windows 10 Install.wim中的所有版本。 我遇到的问题是,一旦WinReducer到达此窗口,您在其中选择了WIM文件中的一个版本,我似乎就无法与Combobox或 Mount 按钮进行交互。 Window I'm stuck at

这是我当前拥有的代码:

; ==== Environment setup ====
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
;ListLines, Off

DetectHiddenWindows, On
SetTitleMatchMode, 1
SetControlDelay, 0
CoordMode, Mouse, Client


; ==== Script ====
; Must run with admin privileges

iControlSelector := 1       ; Need to change this to find number of images present in Wim
While iControlSelector < 4  ; Set to the total number of images + 1
{
    WinReducerStartup()
    WinGet, iWinReducerPID, PID, WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe,
    ControlClick, WindowsForms10.COMBOBOX.app.0.141b42a_r36_ad11, Open a Folder ... ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA, 
    Control, Choose, %iControlSelector%, WindowsForms10.COMBOBOX.app.0.141b42a_r36_ad11, Open a Folder ... ahk_exe WinReducerEX100_x64.exe,
    WinReducerImageProcess("WinReducerEX100.wccf", 0)
    Process, WaitClose, %iWinReducerPID%
    FileDelete, %A_ScriptDir%\WORK\EXTRACT\ExtractedByWinReducer\WinReducerEX100.wccf
    iControlSelector += 1
}

MoveFilesAndFolders(A_ScriptDir . "\WinReducerEX100_x64\WORK\EXTRACT\ExtractedByWinReducer\*", A_ScriptDir . "\NTLite\Extract")

ExitApp



; ==== Functions ====
WinReducerStartup()
{
    Run, %A_ScriptDir%\WinReducerEX100_x64\WinReducerEX100_x64.exe, 
    SkipWinReducerActivateDialog()
    Sleep, 2000
    WaitThenClick("WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe", "WindowsForms10.BUTTON.app.0.141b42a_r36_ad13")
    Sleep, 400
    ControlClick, WindowsForms10.BUTTON.app.0.141b42a_r36_ad15, WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    SkipWinReducerActivateDialog()
    WaitThenClick("Browse For Folder ahk_exe WinReducerEX100_x64.exe", "Button2")
    WinWait, Open a Folder ... ahk_exe WinReducerEX100_x64.exe,
    WinActivate, Open a Folder ... ahk_exe WinReducerEX100_x64.exe,
    Return
}

WinReducerImageProcess(sConfigFile, iSecondPass:=0)
{
    ;ControlClick, WindowsForms10.BUTTON.app.0.141b42a_r36_ad11, Open a Folder ... ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
;   ControlClick, MOUNT, Open a Folder ... ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    ControlClick, MOUNT, Open a Folder ... ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, ,
    SkipWinReducerActivateDialog()
    WinWait, Open a Folder ... ahk_class WindowsForms10.Window.8.app.0.141b42a_r36_ad1 ahk_exe WinReducerEX100_x64.exe,
    SkipWinReducerActivateDialog()
    WaitThenClick("WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe", "WindowsForms10.BUTTON.app.0.141b42a_r36_ad12")
    SkipWinReducerActivateDialog()
    WaitThenClick("ahk_class #32770 ahk_exe WinReducerEX100_x64.exe", "Button1")
    WaitThenClick("WinReducer Custom Configuration File Restore ahk_class #32770 ahk_exe WinReducerEX100_x64.exe", "Edit2")
    ControlSend, Edit2, ^AD:\Windows_NT_development\WinReducerEX100_x64{Enter}, WinReducer Custom Configuration File Restore ahk_class #32770 ahk_exe WinReducerEX100_x64.exe,
    ControlClick, DirectUIHWND2, WinReducer Custom Configuration File Restore ahk_class #32770 ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    ControlSend, DirectUIHWND2, ^A%sConfigFile%, WinReducer Custom Configuration File Restore ahk_class #32770 ahk_exe WinReducerEX100_x64.exe,
    ControlClick, Button1, WinReducer Custom Configuration File Restore ahk_class #32770 ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    WaitThenClick("Activate Unattended Options ahk_class #32770 ahk_exe WinReducerEX100_x64.exe", "Button1")    ; Okay to delete previous Autounattended.xml
    Sleep, 100
    WaitThenClick("ahk_class #32770 ahk_exe WinReducerEX100_x64.exe", "Button1")
    If iSecondPass = 1
    {
        CopyFilesAndFolders(A_ScriptDir . "\WinReducerEX100_x64\WORK\MOUNT\Copy-Paste to mount directory\*", A_ScriptDir . "\WinReducerEX100_x64\WORK\MOUNT\TEMP_Windows")
        RunWait, %A_WinDir%\System32\Dism.exe /Image:%A_ScriptDir%\WinReducerEX100_x64\WORK\MOUNT\TEMP_Windows /Import-DefaultAppAssociations:%A_ScriptDir%\WinReducerEX100_x64\WORK\MOUNT\FileAssociations.xml,
        WinActivate, WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe,
    }
    WaitThenClick("WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe", "WindowsForms10.BUTTON.app.0.141b42a_r36_ad17")
    Sleep, 500
    ControlClick, WindowsForms10.BUTTON.app.0.141b42a_r36_ad14, WinReducer EX-100 - v ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    SkipWinReducerActivateDialog()
    WaitThenClick("Start WinReducer Process ahk_class #32770 ahk_exe WinReducerEX100_x64.exe", "Button1")
    Return
}

SkipWinReducerActivateDialog()
{
    WinWait, Activate your WinReducer Edition ? ahk_exe WinReducerEX100_x64.exe, 
    ControlClick, WindowsForms10.BUTTON.app.0.141b42a_r36_ad11, Activate your WinReducer Edition ? ahk_exe WinReducerEX100_x64.exe, , LEFT, 1, NA,
    PostMessage, 0x112, 0xF060, , , Activate your WinReducer Edition ? ahk_exe WinReducerEX100_x64.exe,     ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
    Return
}

WaitThenClick(sWinName, sControl)
{
    WinWait, %sWinName%, 
    ControlClick, %sControl%, %sWinName%, , LEFT, 1, NA,
}

MoveFilesAndFolders(sSourcePattern, sDestinationFolder, iDoOverwrite = false)
; Moves all files and folders matching sSourcePattern into the folder named sDestinationFolder and
; returns the number of files/folders that could not be moved. This function requires [v1.0.38+]
; because it uses FileMoveDir's mode 2.
{
    If iDoOverwrite = 1
        iDoOverwrite = 2  ; See FileMoveDir for description of mode 2 vs. 1.
    ; First move all the files (but not the folders):
    FileMove, %sSourcePattern%, %sDestinationFolder%, %iDoOverwrite%
    ; Now move all the folders:
    Loop, %sSourcePattern%, 2  ; 2 means "retrieve folders only".
    {
        FileMoveDir, %A_LoopFileFullPath%, %sDestinationFolder%\%A_LoopFileName%, %iDoOverwrite%
    }
    Return
}

CopyFilesAndFolders(sSourcePattern, sDestinationFolder, iDoOverwrite = false)
; Copies all files and folders matching sSourcePattern into the folder named sDestinationFolder and
; returns the number of files/folders that could not be copied.
{
    ; First copy all the files (but not the folders):
    FileCopy, %sSourcePattern%, %sDestinationFolder%, %iDoOverwrite%
    ; Now copy all the folders:
    Loop, %sSourcePattern%, 2  ; 2 means "retrieve folders only".
    {
        FileCopyDir, %A_LoopFileFullPath%, %sDestinationFolder%\%A_LoopFileName%, %iDoOverwrite%
    }
    Return
}

0 个答案:

没有答案