MightyWeird Posted December 21, 2021 Share Posted December 21, 2021 (edited) Hi, I want to automate the Eset online scanner, because I like to scan a lot...:-) Eset online scanner The problem that I have is after the scan is done there is a hyperlink / button to save the logfile. I am trying for days now to get this "save logfile" clicked, I always get a error when finding this Hyperlink / button code so far... expandcollapse popup#RequireAdmin #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "UIA_Functions.au3" ; #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 While Not IsObj($oWindow1) $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ;~ If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ;~ ConsoleWrite( "$oWindow1 OK" & @CRLF ) If IsObj( $oWindow1 ) Then ConsoleWrite( "$oWindow1 OK" & @CRLF) Else Sleep(1000) ConsoleWrite("Debug, scherm nog niet gevonden..." & @CRLF) EndIf WEnd ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditionauto $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "59648", $pConditionauto ) If Not $pConditionauto Then Return ConsoleWrite( "$pConditionauto ERR" & @CRLF ) ConsoleWrite( "$pConditionauto OK" & @CRLF ) Local $pPane1, $oPane1 $oWindow1.FindFirst( $TreeScope_Descendants, $pConditionauto, $pPane1 ) $oPane1 = ObjCreateInterface( $pPane1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPane1 ) Then Return ConsoleWrite( "$oPane1 ERR" & @CRLF ) ConsoleWrite( "$oPane1 OK" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_HyperlinkControlTypeId, $pCondition1 ) ;~ $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Scanlogboek opslaan", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pHyperlink1, $oHyperlink1 $oPane1.FindFirst( $TreeScope_Descendants, $pCondition1, $pHyperlink1 ) $oHyperlink1 = ObjCreateInterface( $pHyperlink1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oHyperlink1 ) Then Return ConsoleWrite( "$oHyperlink1 ERR" & @CRLF ) ConsoleWrite( "$oHyperlink1 OK" & @CRLF ) Endfunc Edited December 21, 2021 by MightyWeird add link to eset online Link to comment Share on other sites More sharing options...
Danyfirex Posted December 21, 2021 Share Posted December 21, 2021 why not to use web driver? Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
MightyWeird Posted December 22, 2021 Author Share Posted December 22, 2021 (edited) I am not familiar with web driver. I thought web driver was only for browsers etc. Because eset online is not browser based, it starts an application, not a web browser.! Therefore I don't think web driver wil work... But I wil look into it.. Edited December 22, 2021 by MightyWeird Format Link to comment Share on other sites More sharing options...
Solution Popular Post LarsJ Posted December 22, 2021 Solution Popular Post Share Posted December 22, 2021 (edited) HTML issuesI assume the error you see in the SciTE console is: $oHyperlink1 ERR When looking at the image of UIASpy, then the code should work. If the code doesn't work anyway, the default procedure is to print the entire element structure of the target window. This is the target window: Note that I have installed a Danish version of ESET Online Scanner. If you test ESET Online Scanner, you can interrupt the scan after a few hundred files and still be allowed to save the log file. If you don't interrupt the scan, it may take a very long time to complete. Element structureYou print the entire element structure of the target window this way: Right-click the target window in the TreeView. Click "Update all childs of element". Right-click the target window in the TreeView again. Click "Create element tree structure". Right-click in the ListView. Select "Copy all items". Paste the copied data into your editor: expandcollapse popup0000 Window: ESET Online Scanner 0001 Pane: PerryShadowWnd 0002 Pane: Der blev ikke fundet nogen truslerLykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslogFortsæt 0003 Pane: Der blev ikke fundet nogen truslerLykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslogFortsæt 0004 Pane 0005 Pane 0006 Pane 0007 Pane 0008 Button 0009 Button 0010 Button 0011 Pane 0012 Pane: Der blev ikke fundet nogen trusler 0013 Pane 0014 Pane 0015 Pane 0016 Text: Der blev ikke fundet nogen trusler 0017 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslog 0018 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner.Gem scanningslog 0019 Pane 0020 Pane: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner. 0021 Pane 0022 Pane 0023 Text: Lykkedes! Scanning er fuldført. Vi har ikke fundet nogen virus eller andre infektioner. 0024 Pane 0025 Pane: Gem scanningslog 0026 Pane 0027 Pane 0028 Text 0029 Text: Gem scanningslog 0030 Pane: Fortsæt 0031 Pane 0032 Button: Fortsæt 0033 Pane 0034 Pane You see the issue in line 0029 near bottom of the output. In line 0029 it's a Text control. In UIASpy it's a Hyperlink control. It's actually not a real mistake. Both controls exist in the HTML code. The immediate reason why different control types are identified is that the Text control is identified through an $oRawViewWalker object, while the Hyperlink control is identified via the ElementFromPoint() method of a $oUIAutomation object. But the underlying reason why the control is identified differently depending on the identification method is that the provider code for the control isn't UIA code but HTML code. This issue has already been discussed several times in recent threads and posts e.g. UI Automation on W10 - Get all texts in a Chrome document and in this and the following posts. The important thing here is that when you execute your UIA code (contained in an au3 file), the code is executed in the same way as when executing code through a $oRawViewWalker object. This also means that the most accurate control is the one you see in the control structure above, i.e. the Text control. The hyperlink control in UIASpy is less accurate. It's simply not possible to identify the control. So it's the Text control that you use to click the Hyperlink. UI Automation codeUse the entire element structure to create Sample code. In UIASpy, you generate Sample code as follows: Sample code menu | Initial code | Complete code Click ESET Online Scanner window in treeview to switch to info listview Select the 3 listview items as shown in the picture Right-click one of the 3 selected listview items | Create sample code Click Gem scanningslog Text in treeview to switch to info listview Select the 2 listview items as shown in the picture Right-click one of the 2 selected listview items | Create sample code Due to the issues with uniquely identifying the control, the only option to click the control is probably to use the UIA_MouseClick() function. Sample code menu | Code snippets... | Right-click Activate (give focus to) a window | Create sample code Sample code menu | Code snippets... | Right-click Mouse click in middle of bounding rectangle | Create sample code Right click code listview | Copy all items Paste the code into your editor When the code is ready to run, it should look like this: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pCondition2, $pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ESET Online Scanner", $pCondition2 ) $oUIAutomation.CreateAndCondition( $pAndCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pAndCondition2, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition3, $pCondition4, $pAndCondition4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pCondition3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gem scanningslog", $pCondition4 ) $oUIAutomation.CreateAndCondition( $pCondition3, $pCondition4, $pAndCondition4 ) If Not $pAndCondition4 Then Return ConsoleWrite( "$pAndCondition4 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition4 OK" & @CRLF ) Local $pText1, $oText1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition4, $pText1 ) $oText1 = ObjCreateInterface( $pText1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oText1 ) Then Return ConsoleWrite( "$oText1 ERR" & @CRLF ) ConsoleWrite( "$oText1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_MouseClick( $oText1 ) ConsoleWrite( "UIA_MouseClick( $oText1 )" & @CRLF ) EndFunc An execution will generate this SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $pAndCondition2 OK $oWindow1 OK --- Find window/control --- $pAndCondition4 OK $oText1 OK --- Code Snippets --- UIA_WinActivate( $oWindow1 ) --- Code Snippets --- UIA_MouseClick( $oText1 ) But the Hyperlink isn't clicked and the Save As dialog box doesn't open. The reason is that the mouse click is performed far outside the Hyperlink control. The UIA_MouseClick() function calculates the bounding rectangle to click a control. Consider the bounding rectangle in the following two images: w=97 for the Hyperlink control in the first image indicates the correct width to use in the UIA_MouseClick() function. The width of 97 pixels is not that important. The important thing is that the width is set small enough for the mouse click to stay within the Hyperlink control. In the erroneous code above, the width w=799 is used for the Text control in the second image resulting in a mouse click performed far outside the Hyperlink control. This is code for the UIA_MouseClick() function copied from UIA_Functions.au3: ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick( $oElement, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc Modify the function this way so that it takes an additional $iBoundRectWidth parameter: ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick1( $oElement, $iBoundRectWidth, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) $aRect[2] = $iBoundRectWidth If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc Insert and use UIA_MouseClick1() in the existing code as follows: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pCondition2, $pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ESET Online Scanner", $pCondition2 ) $oUIAutomation.CreateAndCondition( $pAndCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pAndCondition2, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition3, $pCondition4, $pAndCondition4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pCondition3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gem scanningslog", $pCondition4 ) ; <<<< Edit text to your own language $oUIAutomation.CreateAndCondition( $pCondition3, $pCondition4, $pAndCondition4 ) If Not $pAndCondition4 Then Return ConsoleWrite( "$pAndCondition4 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition4 OK" & @CRLF ) Local $pText1, $oText1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition4, $pText1 ) $oText1 = ObjCreateInterface( $pText1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oText1 ) Then Return ConsoleWrite( "$oText1 ERR" & @CRLF ) ConsoleWrite( "$oText1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) ;UIA_MouseClick( $oText1 ) UIA_MouseClick1( $oText1, 97 ) ;ConsoleWrite( "UIA_MouseClick( $oText1 )" & @CRLF ) ConsoleWrite( "UIA_MouseClick1( $oText1, 97 )" & @CRLF ) EndFunc ; $fScale is the screen scaling factor ; $fScale values: 1.25, 1.50, ... 4.00 Func UIA_MouseClick1( $oElement, $iBoundRectWidth, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) $aRect[2] = $iBoundRectWidth If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc An execution will generate this SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $pAndCondition2 OK $oWindow1 OK --- Find window/control --- $pAndCondition4 OK $oText1 OK --- Code Snippets --- UIA_WinActivate( $oWindow1 ) --- Code Snippets --- UIA_MouseClick1( $oText1, 97 ) And now the Hyperlink control is clicked and the Save As dialog box opens: 7z-fileESETOnlineScanner.7z Edited December 22, 2021 by LarsJ MightyWeird, mLipok, Danyfirex and 3 others 6 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
MightyWeird Posted December 29, 2021 Author Share Posted December 29, 2021 (edited) Thank you Larsj!, This would take me ages to figure it out. If anyone is interested I posted the complete working script (or should i start a new topic?). It is rough and might needs some improvements, but I am new to autoit and UIA, so please be kind.... The script copies eset folder from an older installation to the target os. So when Eset start, I dont get the initial setup screens. After the scan it looks for a specific window (virus found or not.) From there it saves the log and exists the program) Language is dutch, so adjust where needed.. Suggestions are welcome, expandcollapse popup_Esetmain() Func _Esetmain() HotKeySet("x", "_Interrupt_HotKey") $fInterrupt = 0 Global $esetsourcefolder = @ScriptDir & "\Resources\ESET\ESETOnlineScanner\" Global $esetdestfolder = @LocalAppDataDir & "\Eset\" Global $ESETPID = Run(@ScriptDir & "\Resources\ESET" & "\esetonlinescanner.exe") DirCopy($esetsourcefolder, $esetdestfolder & "\ESETOnlineScanner\", $FC_OVERWRITE) Winwait("[CLASS:#32770]","") ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ;bij instellingen toepassing vewijderen aanzetten! Local $pConditionesetwin0, $pConditionesetwin1, $pAndConditionesetwin1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pConditionesetwin0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pConditionesetwin1 ) $oUIAutomation.CreateAndCondition( $pConditionesetwin0, $pConditionesetwin1, $pAndConditionesetwin1 ) If Not $pAndConditionesetwin1 Then Return ConsoleWrite( "$pAndConditionesetwin1 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionesetwin1 OK" & @CRLF ) Local $pConditionesetwin2, $pAndConditionesetwin2 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "ESET Online Scanner", $pConditionesetwin2 ) $oUIAutomation.CreateAndCondition( $pAndConditionesetwin1, $pConditionesetwin2, $pAndConditionesetwin2 ) If Not $pAndConditionesetwin2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionesetwin2 OK" & @CRLF ) Local $pWindow1, $oWindow1 While Not IsObj($oWindow1) $oDesktop.FindFirst( $TreeScope_Children, $pAndConditionesetwin2, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $oWindow1 ) Then ConsoleWrite( "$oWindow1 OK" & @CRLF) Else Sleep(500) ConsoleWrite("Debug, scherm nog niet gevonden..." & @CRLF) EndIf WEnd ; instellingen openen UIA_WinActivate( $oWindow1 ) Local $pConditioninstellingen1,$pConditioninstellingen2,$pAndConditioninstellingen $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pConditioninstellingen1 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Instellingen", $pConditioninstellingen2 ) $oUIAutomation.CreateAndCondition( $pConditioninstellingen1, $pConditioninstellingen2, $pAndConditioninstellingen) If Not $pAndConditioninstellingen Then Return ConsoleWrite( "$pAndConditioninstellingen ERR" & @CRLF ) ConsoleWrite( "$pAndConditioninstellingen OK" & @CRLF ) Local $pinstellingenbtn, $oinstellingenbtn While Not IsObj($oinstellingenbtn) $oDesktop.FindFirst( $TreeScope_Descendants, $pAndConditioninstellingen, $pinstellingenbtn ) $oinstellingenbtn = ObjCreateInterface( $pinstellingenbtn, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $oinstellingenbtn ) Then ConsoleWrite( "$oinstellingenbtn OK / scherm met instelingen gevonden" & @CRLF ) Else ConsoleWrite("Debug, Error, $oinstellingenbtn nog niet gevonden..." & @CRLF) Sleep(5000) ;hier nog interrupt!!!! EndIf WEnd UIA_mouseclick($oinstellingenbtn) consolewrite ("Debug, knop instellingen indrukken") ;knoppen identificeren / toepassing verwijderen Local $pConditioninstellingencheck1,$pConditioninstellingencheck2,$pAndConditioninstellingencheck $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_CheckBoxControlTypeId, $pConditioninstellingencheck1 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Toepassingsgegevens verwijderen tijdens sluiten", $pConditioninstellingencheck2 ) $oUIAutomation.CreateAndCondition( $pConditioninstellingencheck1, $pConditioninstellingencheck2, $pAndConditioninstellingencheck) If Not $pAndConditioninstellingencheck Then Return ConsoleWrite( "$pAndConditioninstellingencheck ERR" & @CRLF ) ConsoleWrite( "$pAndConditioninstellingencheck OK" & @CRLF ) Local $pinstellingencheckbtn, $oinstellingencheckbtn While Not IsObj($oinstellingencheckbtn) $oDesktop.FindFirst( $TreeScope_Descendants, $pAndConditioninstellingencheck, $pinstellingencheckbtn ) $oinstellingencheckbtn = ObjCreateInterface( $pinstellingencheckbtn, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $oinstellingencheckbtn ) Then ConsoleWrite( "$oinstellingencheckbtn OK" & @CRLF ) Else ConsoleWrite("Debug, Error, $oinstellingencheckbtn nog niet gevonden..." & @CRLF) Sleep(5000) ;hier nog interrupt!!!! EndIf WEnd sleep(2000) ;toepassing verwijderen indrukken UIA_mouseclick($oinstellingencheckbtn) consolewrite ("Debug, Toepassingsgegevens verwijderen indrukken" & @CRLF ) WinActivate("ESET Online Scanner") ControlClick(("ESET Online Scanner"), "", "") ;Dit ooit nog eens automatiseren ipv via send... send ("{tab 4}") sleep (2000) send ("{space}") ################################### instellingen ########################## ;knoppen identificeren / toepassing verwijderen Local $pCondition1,$pCondition2,$pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Computerscan", $PropertyConditionFlags_MatchSubstring, $pCondition2 ) $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pButton1, $oButton1 While Not IsObj($oButton1) $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition2, $pButton1 ) $oButton1 = ObjCreateInterface( $pButton1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $oButton1 ) Then ConsoleWrite( "$oButton1 OK" & @CRLF ) Else ConsoleWrite("Debug, Error, $OButton1 nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf WEnd UIA_mouseclick($obutton1) ConsoleWrite("debug, volldige scan knop indrukken" & @CRLF) Sleep(1000) ;wacht op volgend scherm Local $pCondition4,$pCondition5,$pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition4 ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Volledige scan", $PropertyConditionFlags_MatchSubstring, $pCondition5 ) $oUIAutomation.CreateAndCondition( $pCondition4, $pCondition5, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pButton3, $oButton3 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pButton3 ) $oButton3 = ObjCreateInterface( $pButton3, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oButton3 ) Then Return ConsoleWrite( "$oButton3 ERR" & @CRLF ) ConsoleWrite( "$oButton3 OK" & @CRLF ) Sleep (1000) UIA_mouseclick($obutton3) ConsoleWrite("debug, Volledige scan knop ingedrukt met mouseclick" & @CRLF) Sleep(1000) ;radio button ongewenste toepassing Local $pConditpotent4,$pconditpotent5,$pAndConditpotent3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_RadioButtonControlTypeId, $pConditpotent4 ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "ESET potentieel ongewenste", $PropertyConditionFlags_MatchSubstring, $pconditpotent5 ) $oUIAutomation.CreateAndCondition( $pConditpotent4, $pconditpotent5, $pAndConditpotent3 ) If Not $pAndConditpotent3 Then Return ConsoleWrite( "$pAndConditpotent3 ERR" & @CRLF ) ConsoleWrite( "$pAndConditpotent3 OK" & @CRLF ) Local $ppotButton3, $opotButton3 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndConditpotent3, $ppotButton3 ) $opotButton3 = ObjCreateInterface( $ppotButton3, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $opotButton3 ) Then Return ConsoleWrite( "$opotButton3 ERR" & @CRLF ) ConsoleWrite( "$opotButton3 OK" & @CRLF ) UIA_mouseclick($opotButton3) ConsoleWrite("debug, Potentieel knop ingedrukt met mouseclick" & @CRLF) sleep (2000) ;Volgende knop Local $pConditionstartscan4,$pConditionstartscan5,$pAndConditionstartscan3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pConditionstartscan4 ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Scan starten", $PropertyConditionFlags_MatchSubstring, $pConditionstartscan5 ) $oUIAutomation.CreateAndCondition( $pConditionstartscan4, $pConditionstartscan5, $pAndConditionstartscan3 ) If Not $pAndConditionstartscan3 Then Return ConsoleWrite( "$pAndConditionstartscan3 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionstartscan3 OK" & @CRLF ) Local $pButtonscanstart3, $oButtonscanstart3 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndConditionstartscan3, $pButtonscanstart3 ) $oButtonscanstart3 = ObjCreateInterface( $pButtonscanstart3, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oButtonscanstart3 ) Then Return ConsoleWrite( "$oButtonscanstart3 ERR" & @CRLF ) ConsoleWrite( "$oButtonscanstart3 OK" & @CRLF ) UIA_mouseclick($oButtonscanstart3) ConsoleWrite("debug, Scan starten knop" & @CRLF) ##############NU scan bezig, wachten op einde scan venster ########################## ;mogelijke vensters beschrijven / identificeren Local $ponderbroken0 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Scan onderbroken door gebruiker", $ponderbroken0 ) If Not $ponderbroken0 Then Return ConsoleWrite( "$ponderbroken0 ERR" & @CRLF ) ConsoleWrite( "$ponderbroken0 OK" & @CRLF ) Local $pdetecties0 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Detecties plaatsgevonden en opgelost",$pdetecties0 ) If Not $pdetecties0 Then Return ConsoleWrite( "$pdetecties0 ERR" & @CRLF ) ConsoleWrite( "$pdetecties0 OK" & @CRLF ) Local $pgeendetecties0 $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Geen bedreigingen gevonden", $PropertyConditionFlags_MatchSubstring, $pgeendetecties0 ) If Not $pgeendetecties0 Then Return ConsoleWrite( "$pgeendetecties0 ERR" & @CRLF ) ConsoleWrite( "$pgeendetecties0 OK" & @CRLF ) ;hier begint de loop (if scan onderbroken / scan voltooid / virus gevonden..e.d) Local $pText1, $oText1,$pText2,$oText2,$pText3,$oText3 While Not IsObj($oText1) Or ($oText2) or ($oText3);while $oDesktop.FindFirst( $TreeScope_Descendants, $ponderbroken0, $pText1 ) $oText1 = ObjCreateInterface( $pText1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) $oDesktop.FindFirst( $TreeScope_Descendants, $pdetecties0, $pText2 ) $oText2 = ObjCreateInterface( $pText2, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) $oDesktop.FindFirst( $TreeScope_Descendants, $pgeendetecties0, $pText3 ) $oText3 = ObjCreateInterface( $pText3, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ; scan onderbroken, nu verder met deze tree... If IsObj( $oText1 ) Then ConsoleWrite( "$oText1 OK" & @CRLF ) Local $pConditiondoogaan1,$pConditiondoorgaan2,$pAndConditiondoorgaan2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pConditiondoogaan1 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Doorgaan", $pConditiondoorgaan2 ) $oUIAutomation.CreateAndCondition( $pConditiondoogaan1, $pConditiondoorgaan2, $pAndConditiondoorgaan2 ) If Not $pAndConditiondoorgaan2 Then Return ConsoleWrite( "$pAndConditiondoorgaan2 ERR" & @CRLF ) ConsoleWrite( "$pAndConditiondoorgaan2 OK" & @CRLF ) Local $pdoorgaanButton1, $odoorgaanButton1 While Not IsObj($odoorgaanButton1) $oWindow1.FindFirst( $TreeScope_Descendants, $pAndConditiondoorgaan2, $pdoorgaanButton1 ) $odoorgaanButton1 = ObjCreateInterface( $pdoorgaanButton1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $odoorgaanButton1 ) Then ConsoleWrite( "$odoorgaanButton1 OK" & @CRLF ) Else ConsoleWrite("Debug, $odoorgaanButton1 nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf WEnd ;einde binnen loop WinActivate("ESET Online Scanner") ControlClick(("ESET Online Scanner"), "", "") UIA_mouseclick($odoorgaanButton1) ;doorgaan knop sleep (1000) exitloop ;hier einde van de loop, doorgaan na wend... Else ConsoleWrite("Debug, $oText1 (onderbroken nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf ;einde $text1 ;virus gevonden, nu verder met deze tree If IsObj( $oText2 ) Then ConsoleWrite( "$oText2 OK" & @CRLF ) Local $pConditionresult0 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_PaneControlTypeId, $pConditionresult0 ) If Not $pConditionresult0 Then Return ConsoleWrite( "$pConditionresult0 ERR" & @CRLF ) ConsoleWrite( "$pConditionresult0 OK" & @CRLF ) Local $pPane1result, $oPane1result $oDesktop.FindFirst( $TreeScope_Descendants, $pConditionresult0, $pPane1result ) $oPane1result = ObjCreateInterface( $pPane1result, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPane1result ) Then Return ConsoleWrite( "$oPane1result ERR" & @CRLF ) ConsoleWrite( "$oPane1result OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditionresult1 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gedetailleerde resultaten weergeven ", $pConditionresult1 ) If Not $pConditionresult1 Then Return ConsoleWrite( "$pConditionresult1 ERR" & @CRLF ) ConsoleWrite( "$pConditionresult1 OK" & @CRLF ) Local $pPaneresult2, $oPaneresult2 $oDesktop.FindFirst( $TreeScope_Descendants, $pConditionresult1, $pPaneresult2 ) $oPaneresult2 = ObjCreateInterface( $pPaneresult2, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPaneresult2 ) Then Return ConsoleWrite( "$oPaneresult2 ERR" & @CRLF ) ConsoleWrite( "$oPaneresult2 OK" & @CRLF ) ;gedetailleerde resultaten weergeven knop Local $pConditionresult4,$pConditionresult5,$pAndConditionresult3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pConditionresult4 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Gedetailleerde resultaten weergeven", $pConditionresult5 ) $oUIAutomation.CreateAndCondition( $pConditionresult4, $pConditionresult5, $pAndConditionresult3 ) If Not $pAndConditionresult3 Then Return ConsoleWrite( "$pAndConditionresult3 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionresult3 OK" & @CRLF ) Local $pButtonresult3, $oButtonresult3 While Not IsObj($oButtonresult3) $oPaneresult2.FindFirst( $TreeScope_Descendants, $pAndConditionresult3, $pButtonresult3 ) $oButtonresult3 = ObjCreateInterface( $pButtonresult3, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If IsObj( $oButtonresult3 ) Then ConsoleWrite( "$oButtonresult3 OK" & @CRLF ) Else ConsoleWrite("Debug, $oButtonresult3 nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf WEnd ;einde binnen loop WinActivate("ESET Online Scanner") ControlClick("ESET Online Scanner", "", "") UIA_mouseclick($oButtonresult3) ;nu logboek opslaan Local $pConditionlogb3, $pConditionlogb4, $pAndConditionlogb4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pConditionlogb3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Scanlogboek opslaan", $pConditionlogb4 ) ; <<<< Edit text to your own language $oUIAutomation.CreateAndCondition( $pConditionlogb3, $pConditionlogb4, $pAndConditionlogb4 ) If Not $pAndConditionlogb4 Then Return ConsoleWrite( "$pAndConditionlogb4 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionlogb4 OK" & @CRLF ) Local $pTextlogb1, $oTextlogb1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndConditionlogb4, $pTextlogb1 ) $oTextlogb1 = ObjCreateInterface( $pTextlogb1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oTextlogb1 ) Then Return ConsoleWrite( "$oTextlogb1 ERR" & @CRLF ) ConsoleWrite( "$oTextlogb1 OK" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) UIA_MouseClick1( $oTextlogb1, 97 ) ConsoleWrite( "UIA_MouseClick1( $oText1, 97 )" & @CRLF ) UIA_WinActivate( $oWindow1 ) Sleep(500) ControlClick("ESET Online Scanner", "Scanlogboek opslaan", 1065) Sleep(500) WinWait("Opslaan als", "") WinActivate("Opslaan als", "") Sleep(500) ControlSend("", "", "", "c:\logs\esetlog.txt") Sleep(500) Send("{Enter}") Sleep(500) ;vervolgens doorgaan knop #################################### Logboek opgeslagen, nu toepassing sluiten #################################################### winclose("[CLASS:#32770]","") ############################################ toepassing Sluiten ############################################################## Local $pConditiontoepassingsluiten1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_PaneControlTypeId, $pConditiontoepassingsluiten1 ) If Not $pConditiontoepassingsluiten1 Then Return ConsoleWrite( "$pConditiontoepassingsluiten1 ERR" & @CRLF ) ConsoleWrite( "$pConditiontoepassingsluiten1 OK" & @CRLF ) Local $pPaneltoepassingsluiten1, $oPaneltoepassingsluiten1 $oDesktop.FindFirst( $TreeScope_Descendants, $pConditiontoepassingsluiten1, $pPaneltoepassingsluiten1 ) $oPaneltoepassingsluiten1 = ObjCreateInterface( $pPaneltoepassingsluiten1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPaneltoepassingsluiten1 ) Then Return ConsoleWrite( "$oPaneltoepassingsluiten1 ERR" & @CRLF ) ConsoleWrite( "$oPaneltoepassingsluiten1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditiontoepassingsluiten2 $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Uw scan resulteert in uw inbox", $PropertyConditionFlags_MatchSubstring, $pConditiontoepassingsluiten2 ) If Not $pConditiontoepassingsluiten2 Then Return ConsoleWrite( "$pConditiontoepassingsluiten2 ERR" & @CRLF ) ConsoleWrite( "$pConditiontoepassingsluiten2 OK" & @CRLF ) Local $pPaneltoepasssingsluiten2, $oPaneltoepassingsluiten2 $oDesktop.FindFirst( $TreeScope_Descendants, $pConditiontoepassingsluiten2, $pPaneltoepasssingsluiten2 ) $oPaneltoepassingsluiten2 = ObjCreateInterface( $pPaneltoepasssingsluiten2, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPaneltoepassingsluiten2 ) Then Return ConsoleWrite( "$oPaneltoepassingsluiten2 ERR" & @CRLF ) ConsoleWrite( "$oPaneltoepassingsluiten2 OK" & @CRLF ) ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditiontoesluiten3, $pConditiontoesluiten4, $pAndConditiontoesluiten4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pConditiontoesluiten3 ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Toepassing sluiten", $PropertyConditionFlags_MatchSubstring, $pConditiontoesluiten4 ) $oUIAutomation.CreateAndCondition( $pConditiontoesluiten3, $pConditiontoesluiten4, $pAndConditiontoesluiten4 ) If Not $pAndConditiontoesluiten4 Then Return ConsoleWrite( "$pAndConditiontoesluiten4 ERR" & @CRLF ) ConsoleWrite( "$pAndConditiontoesluiten4 OK" & @CRLF ) Local $ptoesluiten1, $otoesluiten1 While Not IsObj($otoesluiten1) $oPaneltoepassingsluiten2.FindFirst( $TreeScope_Descendants, $pAndConditiontoesluiten4, $ptoesluiten1 ) $otoesluiten1 = ObjCreateInterface( $ptoesluiten1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If IsObj( $otoesluiten1 ) Then ConsoleWrite( "$otoesluiten1 OK" & @CRLF ) Else ConsoleWrite("Debug, $otoesluiten1 nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf wend UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) UIA_MouseClick( $otoesluiten1 ) consolewrite("Debug, exitloop einde script, op naar volgende functie" & @CRLF) exitloop Else ConsoleWrite("Debug, $oText2 (detecties nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf ###################################################################################################### #################### Geen Virus ################### ###################################################################################################### UIA_WinActivate( $oWindow1 ) If IsObj( $oText3 ) Then ; scan klaar, geen virus ConsoleWrite( "$oText3 OK" & @CRLF ) Local $pConditionlogbgv3, $pConditionlogbgv4, $pAndConditionlogbgv4 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TextControlTypeId, $pConditionlogbgv3 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Scanlogboek opslaan", $pConditionlogbgv4 ) ; <<<< Edit text to your own language $oUIAutomation.CreateAndCondition( $pConditionlogbgv3, $pConditionlogbgv4, $pAndConditionlogbgv4 ) If Not $pAndConditionlogbgv4 Then Return ConsoleWrite( "$pAndConditionlogbgv4 ERR" & @CRLF ) ConsoleWrite( "$pAndConditionlogbgv4 OK" & @CRLF ) Local $pTextlogb1gv, $oTextlogb1gv $oDesktop.FindFirst( $TreeScope_Descendants, $pAndConditionlogbgv4, $pTextlogb1gv ) $oTextlogb1gv = ObjCreateInterface( $pTextlogb1gv, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If Not IsObj( $oTextlogb1gv ) Then Return ConsoleWrite( "$oTextlogb1gv ERR" & @CRLF ) ConsoleWrite( "$oTextlogb1gv OK" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) UIA_MouseClick1( $oTextlogb1gv, 97 ) ConsoleWrite( "UIA_MouseClick1( $oText1, 97 )" & @CRLF ) UIA_WinActivate( $oWindow1 ) Sleep(500) ControlClick("ESET Online Scanner", "Scanlogboek opslaan", 1065) Sleep(500) WinWait("Opslaan als", "") WinActivate("Opslaan als", "") Sleep(500) ControlSend("", "", "", "c:\logs\esetlog.txt") Sleep(500) Send("{Enter}") Sleep(500) ##################### Logboek opgeslagen, nu toepassing sluiten #################################################### winclose("[CLASS:#32770]","") ############################################ toepassing Sluiten ############################################################## Local $pConditiontoepassingsluiten1gv $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_PaneControlTypeId, $pConditiontoepassingsluiten1gv ) If Not $pConditiontoepassingsluiten1gv Then Return ConsoleWrite( "$pConditiontoepassingsluiten1gv ERR" & @CRLF ) ConsoleWrite( "$pConditiontoepassingsluiten1gv OK" & @CRLF ) Local $pPaneltoepassingsluiten1gv, $oPaneltoepassingsluiten1gv $oDesktop.FindFirst( $TreeScope_Descendants, $pConditiontoepassingsluiten1gv, $pPaneltoepassingsluiten1gv ) $oPaneltoepassingsluiten1gv = ObjCreateInterface( $pPaneltoepassingsluiten1gv, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPaneltoepassingsluiten1gv ) Then Return ConsoleWrite( "$oPaneltoepassingsluiten1gv ERR" & @CRLF ) ConsoleWrite( "$oPaneltoepassingsluiten1gv OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditiontoepassingsluiten2gv $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Uw scan resulteert in uw inbox", $PropertyConditionFlags_MatchSubstring, $pConditiontoepassingsluiten2gv ) If Not $pConditiontoepassingsluiten2gv Then Return ConsoleWrite( "$pConditiontoepassingsluiten2gv ERR" & @CRLF ) ConsoleWrite( "$pConditiontoepassingsluiten2gv OK" & @CRLF ) Local $pPaneltoepasssingsluiten2gv, $oPaneltoepassingsluiten2gv $oDesktop.FindFirst( $TreeScope_Descendants, $pConditiontoepassingsluiten2gv, $pPaneltoepasssingsluiten2gv ) $oPaneltoepassingsluiten2gv = ObjCreateInterface( $pPaneltoepasssingsluiten2gv, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oPaneltoepassingsluiten2gv ) Then Return ConsoleWrite( "$oPaneltoepassingsluiten2gv ERR" & @CRLF ) ConsoleWrite( "$oPaneltoepassingsluiten2gv OK" & @CRLF ) ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pConditiontoesluiten3gv, $pConditiontoesluiten4gv, $pAndConditiontoesluiten4gv $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pConditiontoesluiten3gv ) $oUIAutomation.CreatePropertyConditionex( $UIA_NamePropertyId, "Toepassing sluiten", $PropertyConditionFlags_MatchSubstring, $pConditiontoesluiten4gv ) $oUIAutomation.CreateAndCondition( $pConditiontoesluiten3gv, $pConditiontoesluiten4gv, $pAndConditiontoesluiten4gv ) If Not $pAndConditiontoesluiten4gv Then Return ConsoleWrite( "$pAndConditiontoesluiten4gv ERR" & @CRLF ) ConsoleWrite( "$pAndConditiontoesluiten4gv OK" & @CRLF ) Local $ptoesluiten1gv, $otoesluiten1gv While Not IsObj($otoesluiten1gv) $oPaneltoepassingsluiten2gv.FindFirst( $TreeScope_Descendants, $pAndConditiontoesluiten4gv, $ptoesluiten1gv ) $otoesluiten1gv = ObjCreateInterface( $ptoesluiten1gv, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) If IsObj( $otoesluiten1gv ) Then ConsoleWrite( "$otoesluiten1gv OK" & @CRLF ) Else ConsoleWrite("Debug, $otoesluiten1gv nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf wend ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) UIA_MouseClick( $otoesluiten1gv ) consolewrite("Debug, exitloop einde script, op naar volgende functie" & @CRLF) exitloop Else ConsoleWrite("Debug, $oText3 (Geen virus nog niet gevonden..." & @CRLF) Sleep(1000) ;hier nog interrupt!!!! EndIf ;Hier interrupt funcite: If $fInterrupt <> 0 Then ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) ;Next ConsoleWrite(">Func 1 Ended" & @CRLF) ;einde interrupt functie wend EndFunc Func UIA_MouseClick1( $oElement, $iBoundRectWidth, $bRight = False, $fScale = 0 ) If Not IsObj( $oElement ) Then Return SetError(1,0,1) ; Rectangle Local $aRect ; l, t, w, h $oElement.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $aRect ) If Not IsArray( $aRect ) Then Return SetError(1,0,1) $aRect[2] = $iBoundRectWidth If $fScale > 1.00 Then $aRect[0] = Round( $aRect[0] * $fScale ) $aRect[1] = Round( $aRect[1] * $fScale ) $aRect[2] = Round( $aRect[2] * $fScale ) $aRect[3] = Round( $aRect[3] * $fScale ) EndIf ; Click element Local $aPos = MouseGetPos() Local $sButton = Not $bRight ? "primary" : "secondary" DllCall( "user32.dll", "int", "ShowCursor", "bool", False ) MouseClick( $sButton, $aRect[0]+$aRect[2]/2, $aRect[1]+$aRect[3]/2, 1, 0 ) MouseMove( $aPos[0], $aPos[1], 0 ) DllCall( "user32.dll", "int", "ShowCursor", "bool", True ) EndFunc Edited December 29, 2021 by MightyWeird mLipok 1 Link to comment Share on other sites More sharing options...
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