Skip to content

Instantly share code, notes, and snippets.

@michaeloyer
Last active February 8, 2020 22:44
Show Gist options
  • Save michaeloyer/755a5373e4fcae46a1c01218e14ab832 to your computer and use it in GitHub Desktop.
Save michaeloyer/755a5373e4fcae46a1c01218e14ab832 to your computer and use it in GitHub Desktop.
An Autoit Script and a VBScript to Demonstrating how to click through dialog boxes on Windows

Instructions

  • Download AutoIt at https://www.autoitscript.com/site/autoit/downloads/ (You can click the 'Download Zip' button to get a portable version of AutoIt so you don't have to install it on a computer)
  • Run Go Through YesNo Box Flow.au3 on AutoIt.exe (You can also click and drag the au3 script file onto the exe file)
  • Run Create YesNo Box Flow.vbs (Just double click and should run in Windows)
  • Press Ctrl-g to have it click 'Yes' or Ctrl-h to have it click 'No'
answer = Msgbox("Yes or no?", VbYesNoCancel, "Yes or No box")
if (answer = vbYes) then
MsgBox "Yes was pressed", VbOk, "Confirmed"
elseif (answer = vbNo) then
MsgBox "No was pressed", VbOk, "Confirmed"
else
MsgBox "Cancelled"
end if
;Equivalent for setting Hotkeys in AHK:
;^g::GoThroughYesFlow
HotKeySet('^g', 'GoThroughYesFlow')
HotKeySet('^h', 'GoThroughNoFlow')
Func GoThroughYesFlow()
; Don't wait forever for the program's box to appear, just wait one second
; Will be '0' if it times out
$windowHandle = WinWait('Yes or No box', '', 1)
If ($windowHandle = 0) Then
; 48 = Exclamation-point icon
MsgBox(48, 'Not Found', 'Window never found to press "Yes"')
Return
EndIf
; Click the button labled as 'Yes' with an underlined 'Y' on the program found in '$windowHandle
; See Au3Info.exe to see that the text is '&Yes', not 'Yes'
ControlClick($windowHandle, '', '&Yes')
; We've started the flow of the program to click through boxes so go ahead and wait forever
; instead of setting a 1 second timeout
$windowHandle = WinWait('Confirmed')
ControlClick($windowHandle, '', 'OK')
EndFunc
Func GoThroughNoFlow()
; $windowHandle is often abbreviated to $hwnd by convention because you're going to 'H'andle a 'W'i'ND'ow
; in case you read someone else's code
$hwnd = WinWait('Yes or No box', '', 1)
If ($hwnd = 0) Then
MsgBox(48, 'Not Found', 'Window never found to press "No"')
Return
EndIf
ControlClick($hwnd, '', '&No')
$hwnd = WinWait('Confirmed')
ControlClick($hwnd, '', 'OK')
EndFunc
; Keep Script Alive for pressing key presses
; This part is just automatic in AHK. Otherwise the script just immediately ends
While 1
; 100 milliseconds
Sleep(100)
WEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment