randomgeeksj Posted March 9, 2018 Posted March 9, 2018 (edited) New to AutoIT and hopeful but frustrated. I have a program, which unfortunately I cannot share, which seems "immune" to the basic AutoIt methods to interact. Starting with the basic scripts for notepad interaction & starting with a simple Menu File , Open ; I've tried send, sendcontrol, mouseclick -- all report "success", with no errors but the window doesn't react as it should (as in menu doesn't open, open file dialog doesn't start, window doesn't hide, window doesn't close). Using AutoITinfo I have been able to view various elements of the program including getting the windows "Class" for the program so the data is available to autoit (?), still no luck. . . Below is a long bit of code (many lines commented out to record failed attempts) with lots of debugging console writes for output to SciTE-Light console area. . . Note I had some issues with directly trying "run" the application but I worked around with a BAT file & start. . . Running under W10 both on personal laptop and W10 VMWare Client, same results. . . expandcollapse popup#include <Constants.au3> #include <MsgBoxConstants.au3> ; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: leveraged from examples by Jonathan Bennett (jon at autoitscript dot com) & others ; Frankensteined by <<ME>> ; Script Function: ; Opens Avultimate tool and attempts to interact with it. ; Having problem which are like ; https://www.autoitscript.com/forum/topic/137684-cannot-get-window-to-close/, except no silent mode, window is clearly visible. ; https://www.autoitscript.com/forum/topic/192688-nvidia-inspector-automation/#comment-1382617 -- Put pauses in between sends, clicks etc. ; https://www.autoitscript.com/forum/topic/180521-shellexecute-and-winwaitactive/#comment-1295977 ; possibly another window stealing focus? ;GetNSetProgramPath() ;attempt to get path to program to "run", went with .BAT file as per below. ;Run ("Avultimate"); should work with path set but doesn't ? tried other methods. ;run("C:\Program Files\HEWLETT-PACKARD\AvUltimate\AvUltimate.exe") ; fails ;run("C:\Users\Public\Desktop\Avultimate") ; .lnk file fails. run("C:\Users\******\Documents\avultimate.bat") ; has 1 line: start "" "C:\Program Files\HEWLETT-PACKARD\AvUltimate\AvUltimate.exe" ; wait for the Avultimate window to become active. local $hWnd = 0 $hWnd = WinWaitActive("Active Health System Viewer","",10) ;return a Window handle. . . ;$hWnd = WinWaitActive("[Class:WindowsForms10.Window.8.app.0.141b42a_r9_ad1","",5) ; attempt to use class from App but that fails(?) didn't pursue further . . if $hWnd = 0 Then Consolewrite ("WinWaitActive Failed: "&@error&@CRLF) exit else Consolewrite ("WinWaitActive returned hWnd="&$hWnd&@CRLF) EndIf local $status = 0 ; by default this program opens maximized, as the only visible window. ; Attempt to set the state of the application -- These DO NOT work yet. . $status = WinSetState($hWnd, "", @SW_HIDE) Consolewrite ("WinSetState Hide: "&$status&" "& @error&@CRLF) ; Wait for 2 seconds. Sleep(2000) ; Set the state of the Notepad window to "show". $status = WinSetState($hWnd, "", @SW_SHOW) Consolewrite ("WinSetState Show: "&$status&" "& @error&@CRLF) ; Wait for 2 seconds. Sleep(2000) ; Now try to open a file by pressing Alt-F and then scrolling down (s) to the Open menu ; I can, in a live window, type Alt-F and get the file menu to open. . . ; currently all of these fail. . . Sleep(1000) $status = Send("!f") Consolewrite ("Send: "&$status&" "& @error&@CRLF) Sleep(1000) $status = Send("{DOWN}{ENTER}") ; found post mentioning Case sensitivity sometimes. Sleep(1000) $status = Send("!F") Consolewrite ("Send2: "&$status&" "&@error&@CRLF) Sleep(1000) Send("{DOWN }{ENTER}") ;found post saying "Send" may not work so try, ControlSend() Class obtained through autoitinfo Sleep(1000) $status = ControlSend($hWnd,"","[Class:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]", "!f") Consolewrite ("ControlSend1 "&$status& " " & @error&@CRLF) Sleep(1000) $status = ControlSend($hWnd,"","[Class:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]", "[DOWN ] [ENTER]") Consolewrite ("ControlSend2: "&$status&" "&@error&@CRLF) ;try uppercase Alt-F Sleep(1000) ControlSend($hWnd,"","[Class:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]", "!F") Sleep(1000) ControlSend($hWnd,"","[Class:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]", "[DOWN ] [ENTER]") ;how about we simply try to click the mouse in current active window ? $status = 0 Sleep(1000) $status = MouseClick($MOUSE_CLICK_LEFT, 22, 37, 1 , 0) ; location, on full screen, of File Menu ConsoleWrite("MouseClick Status = "&$status &" " & @error&@CRLF) Sleep(1000) $status = MouseClick($MOUSE_CLICK_LEFT, 55, 57, 1 , 0) ; location, on full screen, of Open item in file menu ConsoleWrite("MouseClick Status = "&$status &" " & @error&@CRLF) ;debugging, remind me, what is the windows handle we got from winwaitactive ? ConsoleWrite("Confirm Handle from WinWaitActive: "& $hWnd & @CRLF) ; Just to be sure, Let's look at at ALL the available handles. . . WinHandleList() $hWnd = 0 ; Checking, is avultimate still the "Active Window"? $hWnd = WinActive("Active Health System Viewer","") ;return a Window handle. . . if $hWnd = 0 Then Consolewrite ("WinActive Failed: "&@error&@CRLF) exit() else Consolewrite ("WinActive, handle of Active Window= "&$hWnd&@CRLF) EndIf ; Attempt to close the Active Window local $status = WinClose($hWnd) ConsoleWrite ("WinClose Status= "&$status&@CRLF) ; because none of my attempts to interact with the application works this message helps me know the script is "Complete" MsgBox ($MB_SYSTEMMODAL, "", "Script is done"& @CRLF & "WinClose status:" & $status) ; Finished! ; FUNCTIONS start here . . . Func GetNSetProgramPath() ; Retrieve the value of the environment variable %PATH%. ; When you assign or retrieve an envorinment variable you do so minus the percentage signs (%). Local $sEnvVar = EnvGet("PATH") ; Display the value of the environment variable %PATH%. MsgBox($MB_SYSTEMMODAL, "", "The environment variable %PATH% has the value of: " & @CRLF & @CRLF & $sEnvVar) ; $sEnvVar = $sEnvVar & "C:\Program Files\HEWLETT-PACKARD\AvUltimate" MsgBox($MB_SYSTEMMODAL, "", "The environment variable %PATH% has the value of: " & @CRLF & @CRLF & $sEnvVar) EnvSet("PATH", $sEnvVar) EndFunc ;==>Example Func WinHandleList() ; Retrieve a list of window handles. Local $aList = WinList() ; Loop through the array displaying only visable windows with a title. For $i = 1 To $aList[0][0] If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then ; MsgBox($MB_SYSTEMMODAL, "", "Title: " & $aList[$i][0] & @CRLF & "Handle: " & $aList[$i][1]) ; switch to console write to avoid MsgBoxes pop-up ConsoleWrite("Title: " & $aList[$i][0] & " Handle: " & $aList[$i][1] & @CRLF ) EndIf Next EndFunc ;==>Example ---- END OF SCRIPT -- SciTE-Lite “Go” output is below; WinWaitActive and WinActive returns seem to confirm that the application window is ACTIVE and remains active throughout the script. I report on status & @error for most of the function calls. so the "1 0" says status = 1, @error = 0 for a particular call, which I think is supposed to mean ALL OK. . . >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\******\*****\AHSTest.au3" WinWaitActive returned hWnd=0x00240650 WinSetState Hide: 1 0 WinSetState Show: 1 0 Send: 1 0 Send2: 1 0 ControlSend1 1 0 ControlSend2: 1 0 MouseClick Status = 1 0 MouseClick Status = 1 0 Confirm Handle from WinWaitActive: 0x00240650 Title: Active Health System Viewer (174 day(s) remaining) HPE Confidential - Internal and Approved Partner Usage ONLY Handle: 0x00240650 Title: C:\Users\*****\*****\AHSTest.au3 - SciTE-Lite [2 of 3] Handle: 0x000406F4 Title: March 2018 trimmed.xlsx - Excel Handle: 0x00120644 Title: PERSONAL.XLSB - Excel Handle: 0x00210A88 Title: AutoIt Help (v3.3.14.3) Handle: 0x005A0CAA . . . . . other cruft . . . Title: Desktop Handle: 0x0009051A Title: Program Manager Handle: 0x00010112 WinActive, handle of Active Window= 0x00240650 WinClose Status= 1 >Exit code: 0 Time: 22.8 Note also when I attempt the final "WinClose" it reports success but the window stays open. . . Edited March 14, 2018 by JLogan3o13 Added Code Tags
Zedna Posted March 9, 2018 Posted March 9, 2018 Search this forum for WindowsForms. These windows/controls are nonstandard ones so different approach is needed ... Resources UDF ResourcesEx UDF AutoIt Forum Search
randomgeeksj Posted March 14, 2018 Author Posted March 14, 2018 OK so I read all ~20 posts containing "WindowsForms" -- Many are just posts saying "read more about WindowsForms" but a few nuggets are out there. I've pointed out a the most helpfulful below. Still I was unable to get anything to work. . . Most annoyingly all functions return "good" status -- while not doing anything for the following items, using send, controlsend, controlclick and even direct call to a . (name) instance (handle) control WindowsForms10.Window.8.app.0.141b42a_r9_ad1 139 0x000C0E6A "File Menu" WindowsForms10.SysTabControl32.app.0.141b42a_r9_ad1 1 0x00181DF2 "Dashboard Tab" WindowsForms10.BUTTON.app.0.141b42a_r9_ad1 1 0x000F1310 *** Button I want to Push This included using the old WndID to confirm AutoITinfo output. I also found the helpful script NET_DumpAllControlNames to confirm I had the correct handles. One difference I found was that the handle I was interested was found as item 139 in this code but AutoITinfo reported instance 142. . . Still the handle in Hex was the same. Found this article to use a DLL call _sendclick -- no luck. . .
BrewManNH Posted March 14, 2018 Posted March 14, 2018 Try this one, might work. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
randomgeeksj Posted March 24, 2018 Author Posted March 24, 2018 OK -- made some progress (this isn't my day job), here's a checkpoint: I found the UIA stuff referenced by BrewManNH. Tried SimpleSpy. It worked on most stuff but would crash (AutoIT v3 Script has stopped working) when I tried it on my special case program. Using SCiTE I could see Exit code: 3221225477 -- Forum search not super helpful but tried. #AutoIt3Wrapper_UseX64=Y & N -- no joy const $cUIA_MAXDEPTH=1000 -- no joy strategic consolewrite found it was blowing up here: $oTW.getparentelement($oUIElement,$pTMPParentHandle) Back to checking the forum.. . . not much but found mention of running simplespy as admin? "simplespy.exe" right click "run as admin" IT WORKS -- at least it doesn't crash. Now to see if the the code it suggests works. . . .
JohnOne Posted March 24, 2018 Posted March 24, 2018 Simple, but is your super secret app running as admin, while your script is not? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
randomgeeksj Posted March 29, 2018 Author Posted March 29, 2018 JohnOne -- AFAIK the application isn't running as admin but not an expert. Just know that running SimpleSpy.exe or ScIT.exe ("GO" simplespy.au3) as admin allows me to capture attributes. HOWEVER the code that is generated still doesn't work. Here's my main code from SimpleSpy, capture which, BTW confirms most, if not all the variable settings I've used previously. . . ConsoleWrite("Setting Vars for Clipboard button" & @CRLF) ; the window title can change as license counts down AND as different files are opened ; so need to use a more basic, shorter name than one captured by simplespy ; Note the behavior (lack of functions working) is same IF I use the long name on the right day/time/file but harder to update every test. . . ; _UIA_setVar("oP1","Title:=Active Health System Viewer (153 day(s) remaining) HPE Confidential - Internal and Approved Partner Usage ONLY;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.141b42a_r9_ad1") ;Active Health System Viewer (155 day(s) remaining) HPE Confidential - Internal and Approved Partner Usage ONLY _UIA_setVar("oP1","Title:=Active Health System Viewer;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.141b42a_r9_ad1") ;Active Health System Viewer (155 day(s) remaining) HPE Confidential - Internal and Approved Partner Usage ONLY _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.141b42a_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.141b42a_r9_ad1") ; _UIA_setVar("oP4","Title:=Dashboard;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.141b42a_r9_ad1") ;Dashboard _UIA_setVar("oP5","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.141b42a_r9_ad1") ; _UIA_setVar("CopyCaseNoteSummarytoClipboard.mainwindow","title:=Copy Case Note Summary to Clipboard;classname:=WindowsForms10.BUTTON.app.0.141b42a_r9_ad1") ;~ Actions split away from logical/technical definition above can come from configfiles ConsoleWrite("Starting Actions" & @CRLF) _UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") _UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") _UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_Action("oP5","highlight") _UIA_Action("oP5","setfocus") _UIA_action("CopyCaseNoteSummarytoClipboard.mainwindow","setfocus") _UIA_action("CopyCaseNoteSummarytoClipboard.mainwindow","Click") ;put a CLICK here to attempt to press button. ****** end of code snip. Unsure why SimpleSply switches between _UIA_A and _UIA_a (upper & lower case) -- assuming that is OK? Running from SciTE, the console will show: Setting Vars for Clipboard button Starting Actions deep find in subtree oP1;Desktop deep find in subtree oP2;Desktop deep find in subtree oP3;Desktop deep find in subtree oP4;Desktop deep find in subtree oP5;Desktop Unsure if "Desktop" is correct or not (?), what is normal for _UIA_Action to output? In the mean time the screen is as shown in the new attachment. The first snip shows that, my funny app comes up full screen and, as the script runs, a RED box highlights on top of it but doesn't correlate to any elements in this application. The second snip shows that teducing the app will reveal that the "box"/"frame" being highlighted was actually the MAIN SciTE edit window. . . So STUCK again -- not only is it not highlighting my app it seems all the Action is going to the SciTE window (? ? ? ) Doc2.docx
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now