Why isnt AutoIt performing a click? - autoit

My Code in AutoIt doesn't click, it opens up the file, but doesn't do anything. Any ideas?
Could it be because there's another Window in between asking for my Administrator Password?
Run("Setup.exe")
WinWait("Mozilla Firefox-Installation", "Willkommen beim ")
WinActivate("Mozilla Firefox-Installation", "Willkommen beim ")
ControlClick("Mozilla Firefox-Installation", "Willkommen beim ", "Abbrechen", "left")

#pragma compile(ExecLevel, requireAdministrator)
#RequireAdmin
Run("Setup.exe")
WinWait("Mozilla Firefox-Installation", "Willkommen beim ")
WinActivate("Mozilla Firefox-Installation", "Willkommen beim ")
ControlClick("Mozilla Firefox-Installation", "Willkommen beim ", "Abbrechen")
The #pragma compile directive to set ExecLevel
to requireAdministrator allows the AutoIt script compiled
to executable, in the manifest, to run as Administrator.
The #RequireAdmin directive allows the executed
au3 file to run as Administrator.
The ControlClick may not be allowed happen if the AutoIt process
is running as not an Administrator and the process to be
automated is running as Administrator.
The optional parameter of left can be omitted form the
ControlClick function call as it is already the default.
Note that Firefox supports a -ms silent install argument
so GUI automation can be avoided.

Related

How do I open a document from R?

I want to open a file from within R.
I can launch the software (graphpad prism) with the following:
system2("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")
I expected this to open my prism file as if I were double clicking on it or running it from cmd, but it didn't:
system2("H:/Graphs/Shell/Templates/NASH4_Standard.pzfx")
I am receiving the message:
Warning message: running command
'H:/Graphs/Shell/Templates/NASH4_Standard.pzfx' had status 127
I see that this is not an error but just a warning. Am I unintentionally "shelling" the document in the background? How would I make sure it pops up as a window?
Status 127 was addressed here, but for launching the software, not opening the document with it.
In Windows environments, you need to call a command line interpreter like CMD prompt or PowerShell. Also, any file path that has spaces needs to be enclosed in double quotes above the quotes needed in R for string literals (the case for your .exe not specific file).
With system() send entire command in one string:
system('cmd /c "H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"')
# POWER SHELL REQUIRES MORE QUOTE ESCAPING (ONLY ONE PAIR W/O SPACES)
system('powershell & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""')
With system2() use the args parameter:
# FILES
system2('cmd', args=c('/c', '"H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"'))
system2('powershell', args=c(' & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""'))
# EXECUTABLES
system2('cmd', args=c('/c', '"C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"'))
system2('powershell', args=c(' & """C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"""'))
shell.exec("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")
does it work for you ?
ps. and shell.exec("MyWorkbook.xls") open file with default program

AutoIt and RSelenium to navigate Save As dialogue (Firefox)

I have been trying now for days (if not weeks...) to get the code below to work. What I am trying to achieve is that an R script runs daily (via batch script and Windows Task Scheduler on Windows Server 2008 64bit).
That R script shall navigate to certain websites, log in and invoke the Save As dialogue to save complete pages to a specific path.
If I run my script on my machine (Win 8 - 64bit) within RStudio it works like a charme - remotely and via Rscript.exe it does not.
The problem appears to be with the SaveAs.au3 script - when I call it via RStudio or from file explorer it works perfectly. The same R Script executed within a batch file with:
"C:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe" "C:\JN\abc.R"
works up until the system() command as well and crahses then without providing any error or warning.
Maybe there is someone who had a similar problem and can help? Thanks!
The 3 AutoIt scripts are the following:
SaveAs.au3 / exe
ControlFocus("[CLASS:MozillaWindowClass]", "", "")
ControlSend("[CLASS:MozillaWindowClass]", "", "", "^s")
EditName.au3 will be variably written from within R and then called
KeyEnter.aut3
ControlFocus("Save as", "", "")
ControlClick("Save as","","[CLASS:Button; INSTANCE:1]")
The R script looks as follows:
# compl is a vector of n href
if(length(compl) != 0) {
foreach(i=1:length(compl)) %do% {
server_check() # checks whether selenium driver is still active and firefox window is open
remDr$navigate(compl[i])
Sys.sleep(10)
login_check() # checks whether login is still active
Sys.sleep(5)
print(paste("attempt to save:",compl[i]))
system('C:\\JN\\SaveAs.exe') # does not matter whether .exe or .au3
Sys.sleep(3)
system("cmd", input = c('echo ControlSetText("Save as", "", "[CLASS:Edit; INSTANCE:1]", "") > C:\\JN\\EditName.au3',
paste0('echo ControlSend("Save as", "", "[CLASS:Edit; INSTANCE:1]", "',
gsub("/","_",gsub(website_url,"", compl[i])), ".htm",
'") >> C:\\JN\\EditName.au3')))
Sys.sleep(3)
system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\EditName.au3')
Sys.sleep(8)
system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\KeyEnter.au3')
Sys.sleep(30)
}
}
print("Complete save end")
The problem was related to Windows Server 2008 R2 - if you disconnect from the remote session the server will initiate a screen server (or alike) making the AutoIt script unable to interact with the GUI (as there is non...)
There are options within Windows Server to prevent the server from disabling the GUI, but my script was still not stable enough to run on its own for months...

system + Sys.which + local directory name with space

It might be very silly what I'm asking, but I'm puzzled and stuck and can't find a solution. I have an executable file in two versions (linux and windows, so e.g. helloworld and helloworld.exe). From the R prompt, I want to call a command for making it run in both OS. So I call it using system and Sys.which but the local directory where they are, it's actually with space in the name so when I do
system(Sys.which("/home/laptop/dont try this at home/helloworld"))
I got
sh: 1: /home/laptop/dont: not found
I guess the error is in system as the shell has the real path with "\" before the space e.g.
/home/semolo/dont\ try\ this\ at\ home
but Sys.which works with "". do you have any idea?
Solution
I got the solution
system(gsub(" ", "\\\\ ", Sys.which("/home/laptop/dont try this at home/helloworld")))

Why does SendKeys produce an error in Windows 7?

I am trying to run this code:
SendKeys "copy /b /y " & outputfile & " " & printerid & "{Enter}", 1.
It runs fine in Windows XP but in Windows 7 it gives an error.
I am trying to copy a string into cmd and execute it.
The "{Enter}" part is giving error.
Please help.
A quick test on Windows 7 gives me:
'sendkeys' is not recognized as an internal or external command,
operable program or batch file.
If that's the same error that you're getting, it means you don't have the program. Try copying it over from XP and see if that works.
If you've already copied it, it might not be in your PATH. Try this:
set PATH=%PATH%;C:\Path\to\SendKeys\
where C:\Path\to\SendKeys is the folder that contains SendKeys.exe.

Console input with Qt Creator

I'm developping a very simple app on my Mac using QtCreator.
It's a console application and I want the user to enter its name, and then I display his name. Here is the code :
#include <iostream>
int main(int ArgC, char* ArgV[])
{
char Name[1000];
std::cout << "Type your name : ";
std::cin >> Name;
std::cout << "Hello " << Name << "\n";
return 0;
}
When running this app with QtCreator, the string "Type your name :" is displayed in the 'Application Output' tab. But if I type some text and press the enter key, nothing is happening.
What's wrong ?
I found a solution. With Qt Creator 1.3.0 (on Mac OS X), here is what I had to do :
Project->Run settings, check "Run in Terminal" (thanks Ropez)
Qt Creator->Preferences : Environnement : General : Terminal : I had to put the whole path to XTerm. For my config, I had to put /usr/x11/bin/xterm -e.
Now, everything is working fine !
Go to Project -> Run settings, and make sure "Run in Terminal" is checked.
BTW:
std::cin >> Name;
is probably not what you want. It will read just a single token (typically only the first name). You should have a look at getline, or the string version.
Jeromes solution is the proper one. Though I can give you a different alternative. In case you don't want to use X11 (for some reason anyhow) in the same position (QtCreator->Preferences->Environment:General:Terminal) you can give your path to the Terminal application like this:
/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
Enjoy!
Solution for Windows.
In the .pro file add:
QT -= core gui
TEMPLATE = app
CONFIG += console
Go to Project -> Run settings, and make sure "Run in Terminal" is checked.
I had the "Cannot start the terminal emulator 'xterm'" problem on Mac and fixed it by going to settings, Environment and clicking the "Reset" button next to the Terminal text field.
For some reason by default it just said "xterm -e" but after the reset it became an absolute path of "/usr/X11/bin/xterm -e".
My console app then ran fine.
For Mac-based Qt 2.4.0, click on the Project vertical tab, which is located below the "Debug" along the same vertical line as Welcome, Edit, Design. In Target-> Run, make sure "Run in terminal" is checked!

Resources