Find the button but can't click it - autoit

The SDK I'm trying to run has first a preparing to install step and then shows the next button. So I'm waiting until I see the button.
When the next button shows up the ConsolWrite writes in the loop. But I'm not able to click the button. Also tried send("!n") and it doesn't work.
#include <GUIConstantsEx.au3>
Global $hCtrl = 0, $Waiting = True
$wintitle = "SigCaptureWeb SDK - InstallShield Wizard"
ShellExecute("C:\SigCaptureWeb.exe")
; your GUI loop
While (1)
If $Waiting And WinExists($wintitle) Then
$hCtrl = ControlGetHandle($wintitle, "", "[CLASS:Button; TEXT:&Next >]")
If $hCtrl Then
; we got the handle, so the button is there
; now do whatever you need to do
ConsoleWrite("in the loop")
ControlClick($wintitle,"", "[CLASS:Button; TEXT:&Next >]","{ENTER}")
$Waiting = False
EndIf
EndIf
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd

You may need to run the script as admin to interact with the installer that runs as admin.
Testing the AutoIt installer with ShellExecute allows the script to detect the window though clicking the button is not working as the script is running as not admin. This could be considered a security feature of the OS to protect the admin process.
This may work for you. I am not sure why you have gui code etc. so I am leaving that out.
; This is a compile directive to make the compiled script run as admin.
#pragma compile(ExecLevel, requireAdministrator)
; This directive is for uncompiled script to run as admin.
#RequireAdmin
$wintitle = "SigCaptureWeb SDK - InstallShield Wizard"
Run("C:\SigCaptureWeb.exe")
WinWait($wintitle)
; Wait for Next button to become visible.
While Not ControlCommand($wintitle, "", "&Next >", "IsVisible", "")
Sleep(250)
WEnd
ControlClick($wintitle, "", "&Next >")
Being an InstallShield installer, it may have arguments that you could pass to the executable to initiate a silent install which may make it easier. You could look into that.

Related

Making AutoIT wait until Audacity completes command

I have a script that I'd like to use to automate processes in Audacity. I have it set up so that all the functions I want to do in Audacity are keyboard shortcuts (since I don't think Audacity uses standard window menus like is required for WinMenuSelectItem()) In other words, my whole code consists of multiple instances of the Send() command. The problem is, AutoIT executes the code too fast. I've tried using WinWait(), but the processes take variable amounts of time. I've also tried ShellExecuteWait() and RunWait()Is there a way to get it to wait until the program isn't doing something, and then execute my send commands? Here's some of my code
Run("C:\Program Files (x86)\Audacity\audacity.exe")
; wait until it's active
WinWaitActive("Audacity")
; get the dialogue box to go away
Send("{ENTER}")
RunWait("Audacity")
; open files
Send("^o")
RunWait("Audacity")
; open the certain file & press enter
Send("test.wav")
RunWait("Audacity")
Send("{ENTER}")
RunWait("Audacity")
; select left boundary of silence period
Send("[")
RunWait("Audacity")
Send("000000100{ENTER}")
RunWait("Audacity")
; select right boundary of silence period
Send("]")
RunWait("Audacity")
Send("200000000{ENTER}")
RunWait("Audacity")
; Use for debugging issues. Systray icon show current line.
Opt('TrayIconDebug', 1)
; Delay default: 250s
Opt('WinWaitDelay', 400)
; Delay default: 5s
Opt('SendKeyDelay', 100)
; Path of the wav file.
$sInFile = #WorkingDir & '\test.wav'
; Optional permanent change of splash screen setting.
_SplashScreen(True)
; Run Audacity and argument of the wav file.
$iPid = Run('"C:\Program Files (x86)\Audacity\audacity.exe" "' & $sInFile & '"')
; Check if Run Audacity failed.
If #error Then
MsgBox(0x40030, #ScriptName, 'Failed to run Audacity')
Exit 1
EndIf
; Wait for main window to get handle. Title is the filename with no extension.
$hMainWindow = WinWait('[TITLE:test; CLASS:wxWindowNR]', '', 10)
; Check allowed timeout of window.
If Not $hMainWindow Then
MsgBox(0x40030, #ScriptName, 'Audacity window not detected.')
Exit 1
EndIf
; If splash screen setting not 0 then handle the window.
If _SplashScreen() Then
AdlibRegister('_WelcomeWindow')
WinWait('Welcome to Audacity', '', 3)
AdlibUnRegister('_WelcomeWindow')
EndIf
; Send '[' to main window to trigger Left Boundary window.
ControlSend($hMainWindow, '', '', '[')
; Get handle of Left Boundary window.
$hMsgWindow = WinWait('Set Left Selection Boundary', '', 5)
; Check allowed timeout of window.
If Not $hMsgWindow Then
MsgBox(0x40030, #ScriptName, 'Selection Boundary window not detected.')
Exit 1
EndIf
; Activate window, set time and click OK.
If WinActivate($hMsgWindow) Then
ControlSend($hMsgWindow, '', 'wxWindowNR1', '{LEFT 3}1'); 1000
ControlClick($hMsgWindow, '', 'Button2'); OK
EndIf
; Send ']' to main window to trigger Right Boundary window.
ControlSend($hMainWindow, '', '', ']')
; Get handle of Right Boundary window.
$hMsgWindow = WinWait('Set Right Selection Boundary', '', 5)
; Check allowed timeout of window.
If Not $hMsgWindow Then
MsgBox(0x40030, #ScriptName, 'Selection Boundary window not detected.')
Exit 1
EndIf
; Activate window, set time and click OK.
If WinActivate($hMsgWindow) Then
; Audacity shows 1000 and focus is on the 1st non zero digit which is 1.
ControlSend($hMsgWindow, '', 'wxWindowNR1', '2'); 2000
ControlClick($hMsgWindow, '', 'Button2'); OK
EndIf
; More code to do.
Sleep(1000)
MsgBox(0x40040, #ScriptName, 'End of automation.' & #CRLF & #CRLF & _
'You can close Audacity to finish.')
; Wait for Audacity process to close.
ProcessWaitClose($iPid)
Exit
Func _WelcomeWindow()
; Used by AdlibRegister to handle the Welcome window.
; Welcome window hides if closed so need to check if exist and is visible (2).
If WinExists('Welcome to Audacity') Then
If BitAND(WinGetState('Welcome to Audacity'), 2) Then
WinClose('Welcome to Audacity')
Else
AdlibUnRegister('_WelcomeWindow')
EndIf
EndIf
EndFunc
Func _SplashScreen($bDisable = False)
; Write to audacity.cfg to disable splash screen.
Local $sIniFile = #AppDataDir & '\Audacity\audacity.cfg'
If IniRead($sIniFile, 'GUI', 'ShowSplashScreen', '1') = '1' Then
If $bDisable Then
; Return 1 if ini file change is success.
If IniWrite($sIniFile, 'GUI', 'ShowSplashScreen', '0') Then
Return 1
EndIf
Else
; Return 1 if check for splash screen is enabled.
Return 1
EndIf
EndIf
EndFunc
Opt() is used to slow down the wait of windows and the sends.
Also added Opt('TrayIconDebug', 1) for debugging though if
the script is considered good then you can remove that Opt().
ControlSend() is used instead of Send() as ControlSend()
targets windows and controls based of title, text, etc.
The Opt() delays are not required though was added to
demonstrate the usage, though perhaps Audacity may struggle
to keep with the speed that AutoIt can automate.
If possible, suggest use of Control*() functions for automation.
Storing window handles in a variable can help save retyping titles
in the code. WinWait() returns a window handle which is ideal and
if the timeout parameter is used, then 0 indicates the window not
found so automation can be aborted.
The Classname of the main window is not enough on its own as
Audacity creates many invisible windows with the same Classname.
So, the title may need to be used as well. The title could be
used alone though titled by filename may not be unique at times.
See Window Titles and Text Advanced for usage.
WinActivate() is used on the Boundary windows although it
may not be needed as control*() usually do not need active
windows. Standard Msgboxes in comparison may require to be
active to accept messages sent to them.
ShellExecuteWait() and RunWait() are no good for automation
as they block the script from continuing until the executed
process has finished.
So use ShellExecute() or Run() instead.
The repetitive use of RunWait("Audacity") seems like
desperation to correct the behavior perhaps, though flawed.
Waiting for windows to appear is how to control flow and then
functions such as ControlCommand() can detect state of controls.
ControlClick() is used on the buttons.
CtrlID of Classname Button2 is used though if the script
is always for English users then you can use the text which
would be OK for the OK button.
The ProcessWaitClose($iPid) is optional.
It is sometimes useful to wait for the program
being automated to exit before the script exits.
You comment "get the dialogue box to go away" in you code
after starting Audacity. You can change the setting on the
dialogue box or Preferences -> Interface options. Advice
disabling as it is a future problem to keep handling.
I added some code to disable the setting in the
audacity.cfg file. If not preferred to disable with
_SplashScreen(True) or done manually then
the AdLibRegister('_WelcomeWindow') call will handle
closing the window. Note that the Welcome window does
not close but rather hides.
_SplashScreen(True) changes splash setting to 0 to disable the splash.
_SplashScreen(False) or _SplashScreen() does no change of settings.
The call returns 1 if splash is enabled else 0.

Qt qaxwidget setcontrol() from file name in order to "xxx.doc" show in widget,but then the winword.exe process can't quit

I've tried two ways to load a Word document into Qt qaxwidget, but neither successfully quits the winword.exe process.
My first attempt
ui->axWidget->setControl("D:/1.doc");
QAxObject *app = ui->axWidget->querySubObject("Application");
app->dynamicCall("Quit()");
Sometimes the following will work, but not reliably:
ui->axWidget->("Word.Application");
setProperty("DisplayAlerts", false);
setProperty("Visible", false);
ui->axWidget->setControl("D:/1.doc");//then call this line of code
QAxObject *app = ui->axWidget->querySubObject("Application");
ui->axWidget->dynamicCall("Close(bool)", false);
ui->axWidget->clear();
app->dynamicCall("Quit()");
What should I do to properly clos thee "winword.exe" process?
My enviroment is qt4.8.0+vs2008.
The first solution should be correct,but there are some other thing that limit me from closing the process.
The second solution is completely an error,When I call ui->axWidget->setControl("D:/1.doc");,"Word.Application" is out of control.
So,we wanna load a Word document into Qt qaxwidget firmly,my solution is
QProcess p;
QString c = "taskkill /im winword.exe /f";
p.execute(c);
p.close();

Check if window has focus with AutoIt

I wonder if it is possible to check to see if a window has focus in AutoIt. I have checked and not found much. I have tried using WinSetOnTop but this didn't seem to do anything so then I considered using WinActivate but this didn't seem to do what I need.
The reason I want to do this is because I have this application I am writing as a prank and I do not want the co-worker on whom I'm playing the prank to just ignore the window when it starts automatically. I am wanting to put a shortcut to it in the startup folder and we have several applications that run on startup and so I want mine to either always be on top or audibly shout rude words at the user if they try and ignore the application.
Is this possible and, if so, can you help me out because I am out of ideas.
Regardless of your motives, you may try WinWaitActive.
Syntax:
WinWaitActive ( "title" [, "text" [, timeout = 0]] )
Example that may be useful to try it out:
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
WinWaitActive("[CLASS:Notepad]", "", 10)
; Wait for 2 seconds to display the Notepad window.
Sleep(2000)
; Close the Notepad window using the classname of Notepad.
WinClose("[CLASS:Notepad]")
EndFunc ;==>Example
Reference:
https://www.autoitscript.com/autoit3/docs/functions/WinWaitActive.htm

How to save inputs in Koda For Designer

I'm really new to AutoIt, I mean like today new, and I'm creating a GUI in Koda form designer. I want to figure out how to save all the input sections in the form so if someone was to open it again it would have their saved inputs.
Cheers
The easiest file format to use from AutoIt for this are ini files. You've probably seen these as configuration files for programs before, windows used to use them for everything.
The following functions are important: IniRead, IniWrite, GUICtrlRead, GUICtrlSetData.
Other types of inputs differ slightly. Checkboxes would require slightly different code, and when using multiline edit controls there are a couple of tricks you can use to get around the ini limitations.
At it's most basic, this is a koda generated form, with a few lines added:
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $sConfigPath = #ScriptDir & "\MySettings.ini"
#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 362, 34, 192, 124)
Local $Input1 = GUICtrlCreateInput("", 8, 8, 346, 20)
#EndRegion ### END Koda GUI section ###
; Here we can execute code before the window is shown
; Get the value of Input1 from the ini file.
GUICtrlSetData($Input1, IniRead($sConfigPath, "inputs", "Input1", ""))
; Show the window afterwards so it looks a bit tidier
GUISetState(#SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
; Note: Exit needs to be changed to ExitLoop
; for any code after the loop to execute.
ExitLoop
EndSwitch
WEnd
; This code will be executed when the window is closed.
; Writes the value of the $Input1 control to the ini file
IniWrite($sConfigPath, "inputs", "Input1", GUICtrlRead($Input1))
That pattern can work for simple forms where you only want to load and save from a single place in the code. When you make more complex GUI's, you'll want to change the loading and saving of inputs to functions, which would allow you to have the normal apply, cancel and ok buttons or even a button to reset to defaults.
And as a final note, it is worth bearing in mind that the AutoIt user base on stackoverflow is very small. Most of our community is on the AutoIt forums. Questions like this will usually have an answer within 10 minutes, compared to a couple of hours here.

Automate LGE Tool with AutoIt

I want to load LGE Tool from an AutoIt script, then go to the tab "Remote Services". I am using this code:
$program = "C:\Program Files (x86)\LGE Tool\LGETool.exe"
If ProcessExists($program) = True Then
MsgBox(0,"","works")
ElseIf ProcessExists($program) = False Then
Run($program)
EndIf
WinActivate($program)
WinWaitActive("LGE Tool version 1.99")
Send("{^TAB}")
The software does load but nothing works after.
Your Send syntax is incorrect...it should be:
Send("^{TAB}")
I'm assuming that Control + TAB works in the program; the software you mentioned is proprietary and requires special drivers, nobody can really test the solution without prerequisites so you've got to be the test point.
Hope this works!
Alex

Resources