Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/14/2019 in all areas

  1. This script works perfect on Windows 7, Excel 2016, single instance and 3 open workbooks Will test with multiple Excel instances soon. #include <Excel.au3> Global $oExcelApp, $oExcelWindow Global $oExcel = _Excel_Open() ; Connect to an already started Excel instance Global $aWorkbooks = _Excel_BookList() ; Get a list of workbooks for all Excel instances ; MsgBox(0, "Info", "Activate a workbook and select a range. 10 Seconds to do", 10) For $i = 0 to UBound($aWorkbooks) - 1 $oExcelApp = $aWorkbooks[$i][0].Parent ; Application object for the selected workbook <== MODIFIED $oExcelWindow = $oExcelApp.ActiveWindow ; Get active Window for the selected Excel instance If IsObj($oExcelWindow) Then ; Is there an active window for this Excel instance? $oExcelActiveCell = $oExcelWindow.ActiveCell ; Get the active cell of the window If @error = 0 Then MsgBox(0, "Result", "Address: " & $oExcelActiveCell.Address & @CRLF & _ "Sheet Name: " & $oExcelApp.ActiveSheet.Name & @CRLF & _ "Book Name: " & $oExcelApp.ActiveWorkbook.Name) ; Displays the selected cell or the top left cell of a range ExitLoop ; If active cell found stop searching EndIf EndIf Next
    2 points
  2. Scheduled Task I do not think this is self elevation related, if it is, my answer does not provide that, you must have elevated privileges to set the task.
    1 point
  3. You really lost me here.... so you are seriously worried about a MITM problem in your private LAN? How would that work assuming you have proper control over the environment? Anyways, all of this is not really important: When you need to transfer sensitive data you need to use an encrypted transmission protocol! .. all the rest of the detection options is Too little Too late. Jos
    1 point
  4. MsgBox (and its A/W variants) are windows OS functions in user32.dll/user32.lib; AutoIt just wraps these.
    1 point
  5. I use the following UDF when parsing comand lines, just don't include "=" sign and you can use something like: /Name "Some really long text" #include <CmdLine.au3> Global $sName = _CmdLine_Get("Name")
    1 point
  6. @editcheck If you use the SciTE4AutoIt3 editor, then you create all the default MsgBoxes that you want with the Abbreviation Manager. You can read more about it in the SciTE4AutoIt3 editor documentation under "Extra Utilities". It looks like this:
    1 point
  7. run those 4 lines please with the maximized books/instances only : Local $aWinList = WinList("[CLASS:XLMAIN]") Local $oXL = _Excel_BookAttach ($aWinList[1][0],"Title") Local $Name = $oXL.ActiveSheet.Name MsgBox (0,"",$Name)
    1 point
  8. Hi! First thanks for this function, very useful! I'm trying to implement this to a code that i'm writing, that check if a class have space or not and if doesn't have, the code will wait till it have space. Like this: $pos[0][0] = 0 While $pos[0][0] = 0 $pos = _BmpSearchEx($hBMP, $hBitmap, 10) Sleep(250) WEnd The problem is, if it takes 1hour till have space for example, the program start with just 12mb of ram used, but after just 2min already use 220mb, and so on. I tried to put the Sleep(250), but that doesn't worked. There is any solution to the function doesn't use so many ram in a while function? Thanks!
    1 point
  9. Quickstart Unzip the 2 zips (UIA*.zip and examples*.zip) of post #1 Start simplespy.au3 Hover your mouse over the element you want to handle Press ctrl+w Copy / paste the given source to a new AutoIT script If you need help ask for help in new thread in general support section and post screenshot that shows your element is highlighted with simplespy post output of simplespy with all properties attached log.txt if available in your script directory use allways contents of latest zip files which could be work in progress (WIP) zip As you will not come far if you do not understand the basics first do this Understand AutoIT http://www.autoitscript.com/autoit3/docs/tutorials/helloworld/helloworld.htm http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm http://www.autoitscript.com/autoit3/docs/tutorials/notepad/notepad.htm Understand testing frameworks and related concepts http://en.wikipedia.org/wiki/Test_automation http://safsdev.sourceforge.net/FRAMESDataDrivenTestAutomationFrameworks.htm http://en.wikipedia.org/wiki/Keyword-driven_testing http://ewildsch.home.xs4all.nl/testautomation.htm If you understand above learn the basic way of setting focus and clicking thru UIA and the wrappers Understand IUIAutomation wrappers and framework Lets do the QuickStart steps as described above on the Start Button of Windows You will get this *** Standard code *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=Pane;class:=Shell_TrayWnd", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("Starten.mainwindow","title:=Starten;classname:=Button") _UIA_action("Starten.mainwindow","setfocus") This code is not yet perfect (and simplespy will improve over time) and you will have to change still manually _UIA_setVar is only used to get a "logical" name for a technical description There are many ways for UIA which varies from simple thru the wrappers to advanced based on the CUIAutomation2.au3 This is better coded #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP0 $oP0=_UIA_action("Title:=;controltype:=Pane;class:=Shell_TrayWnd", "getobject") _UIA_Action($oP0,"move") _UIA_action("title:=Starten;classname:=Button;controltype:=Button","move") _UIA_action("title:=Starten;classname:=Button;controltype:=Button","invoke") ;~ _UIA_action("title:=Start.*;classname:=Button;instance:=2","move") ;~ _UIA_action("title:=Start.*;classname:=Button;instance:=2","invoke") Exercise Learn first to automate some simple stuff on notepad.exe and calc.exe by starting those applications and with ctrl+w within simplespy try some code snippets See for latest examplecode the zip in first post Example 1 Iterating thru the different ways of representing the objects in the tree a. Autoit WinList function b. UIAutomation RawViewWalker c. UIAutomation ControlViewWalker d. UIAutomation ContentViewWalker e. Finding elements based on conditions (based on property id, frequently search on name or classname) ;~ Example 1 Iterating thru the different ways of representing the objects in the tree ;~ a. Autoit WinList function ;~ b. UIAutomation RawViewWalker ;~ c. UIAutomation ControlViewWalker ;~ d. UIAutomation ContentViewWalker ;~ e. Finding elements based on conditions (based on property id, frequently search on name or classname) #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ;~ To prevent some FAQ questions consolewrite("*** Some important settings you can find in " & @scriptdir & "\UIA.CFG ***" & @CRLF) consolewrite("*** " & _UIA_getVersionInfoString() ) consolewrite("*** If logging is turned on you can find it here :" & _UIA_getVar("logFileName") & @CRLF) samplewinlist() sampleTW(1) sampleTW(2) sampleTW(3) ConsoleWrite("**** Desktop windows ****" & @CRLF) findThemAll($UIA_oDesktop, $TreeScope_Children) ConsoleWrite(@CRLF & "**** All childs of the taskbar ****") $oTaskBar = _UIA_gettaskbar() findThemAll($oTaskBar, $treescope_subtree) ConsoleWrite(@CRLF & "**** Deal with browser windows ****" & @CRLF) Local $myBrowser ;- Just get the first browser we can find $myBrowser=getBrowser() $tReturn=MsgBox($MB_SYSTEMMODAL + $MB_OKCANCEL , "Title", "Make sure you have 2 chrome browsers open otherwise press X button to abort.") if $tReturn<>$IDOK Then ConsoleWrite(@CRLF & "**** ABORTING chrome browser demo ****" & @CRLF) exit EndIf consolewrite(@CRLF & "**** Continue with finding 2 browser windows ****" & @CRLF) ;- Just get the first browser we can find of this type $browserType= "Google Chrome" ;~ $browserType= "Internet Explorer" ;~ $browserType= "Opera" $myBrowser=getBrowser($browserType,1) if isobj($myBrowser) Then consolewrite("Yes found first browser " & @CRLF) endif ConsoleWrite(@CRLF & "**** Deal with 2nd browser window****" & @CRLF) ;- Just get the 2nd browser we can find of this type $myBrowser=getBrowser($browserType,2) if isobj($myBrowser) Then consolewrite("Yes found second browser " & @CRLF) Else consolewrite("No 2nd browser found so unable to focus and highlight " & @CRLF) exit endif _UIA_Action($myBrowser,"setfocus") _UIA_Action($myBrowser,"highlight") Func sampleWinList() ConsoleWrite("sample winlist (title not empty and visible windows only)" & @CRLF) Local $hTimer = TimerInit() Local $var = WinList() For $i = 1 To $var[0][0] ; Only display visble windows If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then ConsoleWrite($i & ": Title=" & $var[$i][0] & @TAB & "Handle=" & $var[$i][1] & " Class=" & _WinAPI_GetClassName($var[$i][1]) & @CRLF) EndIf Next Local $fDiff = TimerDiff($hTimer) Consolewrite("SampleWinList took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>sampleWinList Func IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Func getBrowser($browserName="",$browserIndex=1) local $iBrowserIdx=0 ;- Create treewalker $UIA_oUIAutomation.RawViewWalker($UIA_pTW) $oTW = ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker) If IsObj($oTW) = 0 Then MsgBox(1, "UI automation treewalker failed", "UI Automation failed failed", 10) EndIf ;~ Get first element $oTW.GetFirstChildElement($UIA_oDesktop, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;~ Iterate all desktopwindows While IsObj($oUIElement) = True local $tName= _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) Local $tHandle= Hex(_UIA_getPropertyValue($oUIElement, $UIA_NativeWindowHandlePropertyId)) Local $tClassName= _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) ;~ Browser normally put their browsername after the - (so this fails when multiple - are in title so thats why we search from right) local $tStr=stringmid($tname,stringinstr($tName,"-", $STR_NOCASESENSE, -1)+2) ;- See if its a browser (based on title it could be done on class but preferred logical name instead of a classname) ;~ Private modes diffferent title to deal with only IE misbehaves ;~ InPrivate - Internet Explorer - [InPrivate] ;~ InPrivate - [InPrivate] ?- Microsoft Edge ;~ Google Chrome (Incognito) ;~ Mozilla Firefox (Private Browsing) ;~ Privé-browsen - Opera< ;~ Fix misbehave if $tStr="[InPrivate]" then $tStr="Internet Explorer" if stringinstr($tStr," (") then $tStr=stringleft($tstr,stringinstr($tStr," (")-1) EndIf ;~ consolewrite("location: " & stringinstr($tName,"-", $STR_NOCASESENSE, -1) & "<" & $tstr & "><" & $tname & "><" & $tclassname & "><" & $tHandle & ">"& @CRLF) $itsABrowserTitle=stringinstr("Google Chrome,Internet Explorer,Mozilla Firefox,Microsoft Edge,Opera",$tStr,$STR_NOCASESENSE ) if $itsABrowserTitle > 0 then ;~ consolewrite("** Potential match ** " & $tStr & ":" & $browserName& @tab & $tname & @tab & $tclassname & @CRLF) if ($browserName=stringleft($tStr,stringlen($browsername))) or ($browserName="") Then ;~ consolewrite("** match ** " & $tStr & ":" & $browserName& @tab & $tname & @tab & $tclassname & @CRLF) $iBrowserIdx=$iBrowserIdx+1 ;~ consolewrite($browserIndex & $iBrowserIdx) if $iBrowserIDX=$browserIndex Then return $oUIElement endif EndIf EndIf $oTW.GetNextSiblingElement($oUIElement, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) WEnd EndFunc ;==>sampleTW Func sampleTW($t) ConsoleWrite("initializing tw " & $t & @CRLF) Local $hTimer = TimerInit() Local $i=0 ;~ ' Lets show all the items of the desktop with a treewalker If $t = 1 Then $UIA_oUIAutomation.RawViewWalker($UIA_pTW) If $t = 2 Then $UIA_oUIAutomation.ControlViewWalker($UIA_pTW) If $t = 3 Then $UIA_oUIAutomation.ContentViewWalker($UIA_pTW) $oTW = ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker) If IsObj($oTW) = 0 Then MsgBox(1, "UI automation treewalker failed", "UI Automation failed failed", 10) EndIf $oTW.GetFirstChildElement($UIA_oDesktop, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) While IsObj($oUIElement) = True ConsoleWrite($i & "Title is: " & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & @TAB & "Handle=" & Hex(_UIA_getPropertyValue($oUIElement, $UIA_NativeWindowHandlePropertyId)) & @TAB & "Class=" & _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) & @CRLF) $oTW.GetNextSiblingElement($oUIElement, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) $i=$i+1 WEnd Local $fDiff = TimerDiff($hTimer) Consolewrite("Sample tw " & $t & " took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>sampleTW Func findThemAll($oElementStart, $TreeScope) Local $hTimer = TimerInit() ;~ Get result with findall function alternative could be the treewalker Dim $pCondition, $pTrueCondition Dim $pElements, $iLength $UIA_oUIAutomation.CreateTrueCondition($pTrueCondition) $oCondition = ObjCreateInterface($pTrueCondition, $sIID_IUIAutomationCondition, $dtagIUIAutomationCondition) ;~ $oCondition1 = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationCondition) ;~ Tricky to search all descendants on html objects or from desktop/root element $oElementStart.FindAll($TreeScope, $oCondition, $pElements) $oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oAutomationElementArray.Length($iLength) For $i = 0 To $iLength - 1; it's zero based $oAutomationElementArray.GetElement($i, $UIA_pUIElement) $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ConsoleWrite("Title is: " & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & @TAB & "Class=" & _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) & @CRLF) Next Local $fDiff = TimerDiff($hTimer) Consolewrite("Findthemall took: " & $fDiff & " milliseconds" & @CRLF & @CRLF) EndFunc ;==>findThemAll edit 21 aug 2014 Added quick start stuff
    1 point
  10. I always did it like this... $hour = @HOUR; $ampm = 'AM'; If $hour >= 12 Then $ampm = 'PM'; If $hour > 12 Then $hour = $hour - 12; EndIf ElseIf $hour = 0 Then $hour = 12; EndIf Just thought it looked neater.
    1 point
×
×
  • Create New...