AutoIt - ControlClick does not work - autoit

I dont know how to make this working or I am missing something - maybe in #include ?
at this point I have:
#RequireAdmin
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
;vcdredist
Run($sDrivers & "\vcredist_x86.exe")
WinWaitActive("vcredist_x86")
;ControlClick("Microsoft Visual C++ 2010 x86 Redistributable Maintenance", "","[CLASS:Button; INSTANCE:3]")
ControlClick("Microsoft Visual C++ 2010 x86 Redistributable Maintenance", "","[ID:105]")
I've checked with AutoIt v3 WIndow Control and arguments inside ControlClick are correct
none of last two lines make AutoIt select desired option.
Any help very much appreciated.

WinWaitActive()
Probably Isn't the thing you're looking for, as it waits for the window to be active for the code to be ran. WinActivate() activates the window.
If you want the code to run when you activate the window, then WinWaitActive() will do.
Also you can avoid having the title in the ControlClick by doing this.
$hWnd = WinWait("vcredist_x86")
WinWaitActive("vcredist_x86")
ControlClick($hWnd, "", "[CLASS FROM AUTOITINFO]", "Left", 1)
Use the Autoit Window Info tool to find the classes if you aren't using it already.
(https://www.autoitscript.com/autoit3/docs/intro/au3spy.htm)
If ControlClick still doesn't work, then you can try using
MouseClick("Left", x, y)
X, Y are the coordinates.

Probably the script is waiting to the window become active WinWaitActive().
In this case you can use a WinActivate before the WinWaitActive to avoid this problem.
If you want a more robust solution you can use this:
While Not WinActive($win)
WinActivate($win)
Sleep(500)
WEnd

I wrote a UDF in AutoIt to wait for controls. posted around here a few times. just feed it the stuff you want and how long, if applicable you want to wait. you can wait forever by default.
However, there is an easier solution, install it in quiet mode. run a command
Run($sDrivers & '\vcredist_x86.exe /q')
now you don't have to poke any buttons. also, it's better not to use ID because if you are testing an application that is changing, the developers can change all that. I use button text as additional search criteria instead. much more reliable and less maintenance on my code.

Have gone through the similar situation for one application while trying to automate that, after trying all the debugging just added the below command and it worked like charm
#RequireAdmin

Related

No Way to get the console handle (Dev-Pascal)

I've tried the simple program for my exercise but if i compiled, it turned give a message "No Way to get the console handle" (Dev-Pascal).
Here's my code:
program square;
uses crt;
var
side,circumference,broad:real;
begin
write('Input the side value of the square: ');
readln(side);
circumference := 4 * side;
broad := side * side;
writeln('The circumference value of the square = ', circumference);
writeln('The abroad value of the square = ', broad);
writeln();
write('Press any key...');
readkey();
end.
thank you for helping and teaching me
i would appreciate
Dev-pascal comes with a 10+ years old Free Pascal version. I really have no idea. Try to run the example on the cmdline to see if dev-pascal is the cause or something else. Temporarily disable security software might also be something to try.
I suppose, you've created a Window Skeleton project.
It has it's description: A Windows skeleton application (no window).
In this case you'll get this error though you code compiles (I've got this error too with your code).
Try to create Console Application project which has it's own description: A standard console-based (MS-DOS) application (Your code has compiled and the program worked as well).
P.S. Can't say what exactly happens -- couldn't find any documentation about errors in Dev-Pas (1.9.2).
My assumption is that skeleton program doesn't imply console window for execution program while console application does.
just close the project and then re-open the pascal source file (.pas). And maybe put "readln;" just before "END.".

How to Right click of File in Windows Explorer by AutoIt

I wish to simulate a right click on a file. This is done by opening a Windows Explorer window and then right clicking on it.
The main issue is finding the location of the file in Windows Explorer. I am currently using Autoit v3.3.8.1.
My code 's first line:
RunWait (EXPLORER.EXE /n,/e,/select,<filepath>)
The next step is the problem. Finding the coordinates of the file.
After that, right clicking at that coordinates (it seems to me at this time) is not a problem....
Some background:
OS: Windows 7 64-bit
Software Languages: C#, Autoit (for scripting)
The Autoit script is called by a code similar to that below:
Process p = new Process();
p.StartInfo.FileName = "AutoItScript.exe";
p.StartInfo.UseShellExecute = false;
p.Start();
The code is compiled into a console class file which is run at startup. The autoit script runs as the explorer window opens up.
It seems as though you are taking the wrong approach to the problem, so I'll answer what you are asking and what you should be asking.
First up though, that line of code is not valid, and is not what you want either. You want to automate the explorer window, and RunWait waits for the program to finish. Furthermore you want those items to be strings, that code would never work.
Finding the item in explorer
The explorer window is just a listview, and so you can use normal listview messages to find the coordinates of an item. This is done most simply by AutoIt's GUIListView library:
#include<GUIListView.au3>
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Local $hList = ControlGetHandle("[CLASS:CabinetWClass]", "", "[CLASS:SysListView32; INSTANCE:1]")
Local $aClient = WinGetPos($hList)
Local $aPos = _GUICtrlListView_GetItemPosition($hList, _GUICtrlListView_GetSelectedIndices($hList))
MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4)
As has already been mentioned, sending the menu key is definitely a better way than having to move the mouse.
Executing a subitem directly
This is how it should be done. Ideally you should never need an explorer window open at all, and everything can be automated in the background. This should always be what you aim to achieve, as AutoIt is more than capable in most cases. It all depends on what item you want to click. If it is one of the first few items for opening the file in various programs, then it is as simple as either:
Using ShellExecute, setting the verb parameter to whatever it is you want to do.
Checking the registry to find the exact command line used by the program. For this you will need to look under HKCR\.ext where ext is the file extension, the default value will be the name of another key in HKCR which has the actions and icon associated with the filetype. This is pretty well documented online, so google it.
If the action is not one of the program actions (so is built into explorer) then it is a little more complex. Usually the best way will be to look at task manager when you start the program and see what it runs. Other things can be found online, for example (un)zipping. Actions like copy, delete, rename, create shortcut, send to... They can all be done directly from AutoIt with the various File* functions.
With more information, it would be possible to give you more specific help.
First, you might want to look at the Microsoft Active Accessibility SDK. In particular look at this interface...
http://msdn.microsoft.com/en-us/library/accessibility.iaccessible.aspx
You can use this to walk the items in the control and find the one with the file name you are looking for and its screen location.
From there, maybe try something like this for simulating the right click.
How can I use automation to right-click with a mouse in Windows 7?
Once you have done the right click, use accessibility again to find the right option on the context menu.
Maybe there's an easier way, you should be able to cobble something together like this if you don't find one. Good luck!
Suppose I have a file named test.txt on D drive. It needs to right click for opening Context Menu. To do this, the following code should work:
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Send('+{F10}')

QLabel setText not displaying text immediately before running other method

I have a basic label that is supposed to indicate to the user that the program is searching directories for several seconds. So it goes like...
self.label.setText(QString("Searching..."))
# method to search directories goes here
self.label.setText(QString("Search Complete"))
My problem is that the label never displays "Searching...". The execution always seems to jump straight to run the method to scan directories, and then the label text is set to "Search Complete" after the method which scans directories has finished.
I'd be grateful if someone could please explain why this is happening or suggest a better way to resolve the problem.
many thanks
Your "method to search directories" is blocking the GUI hence QLabel is not able to update the text. You can make your search routine asynchronous or go the easy way and force QLabel to update itself:
self.label.setText(QString("Searching..."))
self.label.repaint()
# method to search directories goes here
self.label.setText(QString("Search Complete"))
Add include:
#include <qapplication.h>
Let Qt process events:
self.label.setText(QString("Searching..."))
qApp->processEvents();
Note: repaint() was not necessarie.
In PyQt5, you don't need to use QString :
self.label.setText("Searching...")
self.label.repaint()
self.label.setText("Search Complete")

Is there a way to wait for and get a key press from a (remote) terminal session?

I've been playing around with some ANSI stuff (like colors etc.) in java and php (from scratch) and I'm trying to find a way to basically wait for a key press. I'd like to have something like the following pseudo code at the end of my main event loop:
If (KeyPressed)
Begin
var event = new KeyboardEvent();
event.Key = ReadKey();
this.BubbleEvent(event);
End
But everything I've been trying over the last couple days fails because the key presses only become available on STDIN after the user has pressed enter.
It doesn't matter much what language you answer in, but java, php, plain old c or c# would be nicest, and I cannot use any really spiffy library stuff because I need to port it to all four of those languages... I need this to work over a telnet or ssh connection, but my research so far suggests it is impossible unless you're working on the local machine.
Please prove me wrong.
The curses function cbreak(3) will disable line-buffering and erase/kill handling. You can do this yourself with stty(1) if you really want.
When your program dies and leaves the terminal in cbreak mode, you can usually use either stty sane or reset to bring the terminal back to a reasonable state.
From within Perl, you can use either the Term::ReadKey or the Curses module to manipulate the terminal. See the Term::ReadKey(3pm) or Curses(3pm) manpage for details.
From within C, you can use either ioctl(2) calls on the terminal device to turn on cbreak mode, or you can use curses. See the ncurses(3) manpage for details.
I know, this is an old thread, but I could not find a suitable answer anywhere else. So with some help from the senior programmers of my company I came up with this:
private void waitKeypress() throws IOException
{
System.in.read();
while ( System.in.available() > 0 )
{
System.in.read();
}
}
The part reading as much input as is available solved my problem that when used multiple times, "System.in.read()" alone does not always wait.
For me this does the trick, I use it like this:
doSomething();
waitKeypress();
doNextThing();
Hope it helps.
Kind regards,
Ralph

How to view Session Variables in Visual Studio 2008 Debugger?

Usually using Visual Studio's debugger is a breeze. Scanning through Locals quickly shows the values of variables, etc. However, I'm at a loss how to find out the values contained in session state variables? Can anyone give me a hand?
Let's say I put a breakpoint right after:
Session["first_name"] = "Rob Roy";
How do I view the value contained in Session["first_name"] from locals?
It's pretty simple to inspect the session during debug. Just put a breakpoint in your code and just highlight your Session code (eg. highlight: Session["first_name"]) then right click and select QuickWatch....
This will setup up a watch on your Session for the value you had defined. You can also inspect other Session elements by adjusting the Expression field in the QuickWatch window and clicking the Reevaluate button.
In VS you can just put 'Session["first_name"]' in the Immediate Window and execute while the code is running. That will return the value that it holds.
If you can't find it go to: View > Other Windows > Command Window, or press Ctrl+W, A
It will look like this:
I know its a bit of a late reply but for anyone else who is interested, I hope this helps!
Isn't it HttpContext.Current.Session("..."), I ask as I haven't used ASP.NET for a long time.

Resources