Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/10/2024 in all areas

  1. You can pass command line parameters to .a3x / .au3 files as well (similar to .exe). Define a constant for the respective version number in the script. If the script is started e.g. with /V (freely definable), you can have the version number returned. This seems to be easier than using a HEX editor.
    2 points
  2. the script uses CUIAutomation2.au3 UDF from https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/ Functions to interact with the taskbar. ; https://www.autoitscript.com/forum/topic/212266-functions-to-interact-with-the-taskbar/ ;---------------------------------------------------------------------------------------- ; Title...........: _TaskBar.au3 ; Description.....: Function to interact with the taskbar. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 2.0 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #NoTrayIcon #include ".Includes\CUIAutomation2.au3" ; * <- "https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/" #include <GUIConstantsEx.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <Array.au3> Example() ;-------------------------------------------------------------------------------------------------------------------------------- Func Example() Local $aTBPos, $sTxt, $a ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ;Get information from NotifyArea $sTxt &= "let's take the Everything program for example" & @CRLF $sTxt &= 'first we find the tray icon in NotifyArea' & @CRLF $sTxt &= '(NotifyArea = $iAreaId 2 )' & @CRLF & @CRLF $sTxt &= ' _TaskBar(2, "something not exist")' & @CRLF & @CRLF $sTxt &= '$sSearchString = "something not exist"' & @CRLF $sTxt &= 'to show us all the results' & @CRLF & @CRLF $sTxt &= 'the console only shows results when it doesn''t match' & @CRLF _Msg($sTxt) _TaskBar(2, "something not exist") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Double-click in NotifyArea $sTxt &= "now we know that the target icon " & @CRLF $sTxt &= "starts with the word 'Everything'" & @CRLF & @CRLF $sTxt &= "Now we can send Click, Right-click, or Double-click" & @CRLF & @CRLF $sTxt &= "send Double-click to tray icon" & @CRLF $sTxt &= "(Double-click = $iActionId 4 )" & @CRLF & @CRLF $sTxt &= ' _TaskBar(2, "Everything", 4)' & @CRLF _Msg($sTxt) $aTBPos = _TaskBar(2, "Everything", 4) $a = $aTBPos[0][1] ConsoleWrite($aTBPos[0][1] & ", Rect: " & $a[0] & ", " & $a[1] & ", " & $a[2] & ", " & $a[3] & @CRLF) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Right-click & send in RunningAppsArea $sTxt &= "now that the window has opened it created a new" & @CRLF $sTxt &= "icon down in the task bar to RunningApps area" & @CRLF & @CRLF $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF $sTxt &= "(Right-click = $iActionId 3 )" & @CRLF & @CRLF $sTxt &= '_TaskBar(1, "Everything", 3, "{UP}{ENTER}")' & @CRLF & @CRLF $sTxt &= '$sOption = "{UP}{ENTER}"' & @CRLF $sTxt &= 'Right-click and Send' & @CRLF _Msg($sTxt) _TaskBar(1, "Everything", 3, "{UP}{ENTER}") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Everything' icon from NotifyArea" & @CRLF $sTxt &= "to OverflowNotifyArea" & @CRLF & @CRLF $sTxt &= '(NotifyArea = $iAreaId 2 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = "OverflowButton" )' & @CRLF & @CRLF $sTxt &= '_TaskBar(2, "Everything", 5, "OverflowButton")' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(2, "Everything", 5, "OverflowButton") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Everything' icon from OverflowNotifyArea" & @CRLF $sTxt &= "back to NotifyArea at old position" & @CRLF & @CRLF $sTxt &= '(OverflowNotifyArea = $iAreaId 3 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = "X:" & $a[2] )' & @CRLF & @CRLF $sTxt &= '_TaskBar(3, "Everything", 5, "X:" & $a[2])' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(3, "Everything", 5, "X:" & $a[2]) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Right-click & send in RunningAppsArea $sTxt &= 'Next step open Notepad' & @CRLF $sTxt &= 'Right-click on tray icon and Pin to taskbar' & @CRLF & @CRLF $sTxt &= 'Right-click and Send 2 UP && ENTER' & @CRLF $sTxt &= ' _TaskBar("Notepad -", 1, 3, "{UP 2}{ENTER}")' & @CRLF _Msg($sTxt) ShellExecute("notepad") WinWaitActive("[CLASS:Notepad]", "") _TaskBar(1, "Notepad -", 3, "{UP 2}{ENTER}") WinClose("[CLASS:Notepad]", "") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Notepad' icon 3 positions to the Left" & @CRLF & @CRLF $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = -3 )' & @CRLF & @CRLF $sTxt &= '_TaskBar(1, "Notepad", 5, -3)' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(1, "Notepad", 5, -3) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Notepad' icon 3 positions to the Right" & @CRLF & @CRLF $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = 3 )' & @CRLF & @CRLF $sTxt &= '_TaskBar(1, "Notepad", 5, 3)' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(1, "Notepad", 5, 3) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Notepad' icon at positions 0" & @CRLF & @CRLF $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = "index:0" )' & @CRLF & @CRLF $sTxt &= '_TaskBar(1, "Notepad", 5, "index:0")' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(1, "Notepad", 5, "index:0") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Click&Drag operation $sTxt &= "now we move 'Notepad' icon at last positions" & @CRLF $sTxt &= "by using $sOption = X:n" & @CRLF & @CRLF $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF $sTxt &= '($sOption = "X:" & @DesktopWidth )' & @CRLF & @CRLF $sTxt &= '_TaskBar(1, "Notepad", 5, "X:" & @DesktopWidth)' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(1, "Notepad", 5, "X:" & @DesktopWidth) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ;Get information from RunningAppsArea $sTxt &= "at this step" & @CRLF $sTxt &= "we trap the Notepad pin with" & @CRLF $sTxt &= "($iActionId 1 = Get the button positions and label.)" & @CRLF & @CRLF $sTxt &= "move the mouse over the Notepad pin" & @CRLF _Msg($sTxt) $aTBPos = _TaskBar(1, "Notepad", 1) $a = $aTBPos[0][1] Local $iMsgBoxAnswer, $bLoop = True While $bLoop If IsMouseOverRect($a) Then $iMsgBoxAnswer = MsgBox(292, "Rect: " & $a[0] & ", " & $a[1] & ", " & $a[2] & ", " & $a[3], "do you want to get out of the loop?") Select Case $iMsgBoxAnswer = 6 ;Yes $bLoop = False EndSelect EndIf Sleep(300) WEnd ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Right-click & send in RunningAppsArea $sTxt &= 'Now UnPin Notepad pin' & @CRLF $sTxt &= 'Right-click and Send UP & ENTER' & @CRLF $sTxt &= 'UnPin from taskbar' & @CRLF & @CRLF $sTxt &= ' _TaskBar(1, "Notepad -", 3, "{UP}{ENTER}")' & @CRLF & @CRLF $sTxt &= 'here attention if there is notepad++ taskpin, it unpin this' & @CRLF $sTxt &= 'because it is more forward and starts with word notepad' & @CRLF _Msg($sTxt) _TaskBar(1, "Notepad", 3, "{UP}{ENTER}") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ; Right-click & send in OverflowNotifyArea $sTxt &= 'Now for (OverflowNotifyArea = $iAreaId 3 ) ' & @CRLF & @CRLF $sTxt &= ' Right-click and Send 5 UP on bluetooth' & @CRLF & @CRLF $sTxt &= ' _TaskBar(3, "bluetooth", 3, "{UP 5}")' & @CRLF & @CRLF _Msg($sTxt) _TaskBar(3, "bluetooth", 3, "{UP 5}") Sleep(5000) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $sTxt = "" ;Get information from RunningAppsArea $sTxt &= "or you can call only with the $iAreaId parameter," & @CRLF $sTxt &= "1 - Get the button positions and labels" & @CRLF $sTxt &= "and take the whole table for any use" & @CRLF & @CRLF $sTxt &= '$aTBPos = _TaskBar(1)' & @CRLF & @CRLF _Msg($sTxt) $aTBPos = _TaskBar(1) _ArrayDisplay($aTBPos) _Msg("Exit") EndFunc ;==>Example ;-------------------------------------------------------------------------------------------------------------------------------- Func _Msg($sMsg) Local $hGui = GUICreate("Msg", 395, 237, @DesktopWidth * 0.1, @DesktopHeight * 0.5, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetFont(11, 400, 0, "DejaVu Sans Condensed") GUICtrlCreateLabel($sMsg, 5, 10, 376, 181) Local $Button_OK = GUICtrlCreateButton("OK", 160, 200, 75, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Button_OK ExitLoop EndSwitch WEnd GUIDelete($hGui) EndFunc ;==>_Msg ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _TaskBar ; Description....: Function to interact with the taskbar. ; Syntax.........: _TaskBar ( $iAreaId = 1, $sSearchString = "@All", $iActionId = 1, $sOption = "", $sUserToolBarPar = "index:1" ) ; Parameters.....: $iAreaId - The ID of Area to interact with. Can be one of the following values: ; 1 - RunningAppsArea - Running applications. (Default) ; 2 - NotifyArea - Notification area. ; 3 - OverflowNotifyArea - Overflow Notification Area. ; $sSearchString - The string to search for in the button labels. Matches partial string from the start. (Default = "@All") ; $iActionId - The action to perform. Can be one of the following values: ; 1 - Get the button positions and labels. (Default) ; 2 - Click on a button with the specified label. ; 3 - Right-click on a button with the specified label. ; 4 - Double-click on a button with the specified label. ; 5 - Click&Drag a button with the specified label to specify X axis place ; $sOption - [optional] Additional parameter required by some commands. (Default = "") ; if $iActionId = 2, $sOption = "SendKeys" - Extra string to send after click. ; "{UP 2}{ENTER}" send 2 UP and ENTER to elect the specify menu ; if $iActionId = 3, $sOption = "SendKeys" - Extra string to send after click. ; "o" send o to select the open menu ; if $iActionId = 5, $sOption = "NumberToMove" - number of place to move, posive = Right, negative = Left ; "3" move button, 3 positions to the Right ; "-3" move button, 3 positions to the Left ; "index:3" move button, to positions 3 ; "X:300" move button, to X coordinate ; "OverflowButton" move button from NotifyArea, to OverflowNotifyArea and vice versa ; Return values..: Success - An 2D Array containing the rect positions of the button that match the search string. ; $a[i][0]=Label, $a[i][1]=$aRect Array | $aRect[0]=Left, $aRect[1]=Top, $aRect[2]=Right, $aRect[3]=Bottom. ; - if $sSearchString does not match, it returns 2D Array of all items. ; Failure - return error message if there is an error. ; Author.........: ioa747 ; Modified.......: ; Related .......: This function uses the CUIAutomation2.au3 "https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/" ; Link ..........: ;-------------------------------------------------------------------------------------------------------------------------------- Func _TaskBar($iAreaId = 1, $sSearchString = "@All", $iActionId = 1, $sOption = "") Local $hWndTray = WinGetHandle("[CLASS:Shell_TrayWnd]") ; Taskbar Local $hOverflowButton = ControlGetHandle($hWndTray, "", "Button2") Local $hToolbar Switch $iAreaId Case 1 ;RunningAppsArea Local $hRebar = ControlGetHandle($hWndTray, "", "[CLASS:ReBarWindow32]") Local $hMSTaskSwWClass = ControlGetHandle($hRebar, "", "[CLASS:MSTaskSwWClass]") $hToolbar = ControlGetHandle($hMSTaskSwWClass, "", "[CLASS:MSTaskListWClass]") Case 2 ;NotifyArea Local $hTrayNotify = ControlGetHandle($hWndTray, "", "[CLASS:TrayNotifyWnd]") Local $hSysPager = ControlGetHandle($hTrayNotify, "", "[CLASS:SysPager]") $hToolbar = ControlGetHandle($hSysPager, "", "ToolbarWindow321") Case 3 ;OverflowNotifyArea Local $hWndOverflow = WinGetHandle("[CLASS:NotifyIconOverflowWindow]") $hToolbar = ControlGetHandle($hWndOverflow, "", "ToolbarWindow321") Case Else Return _EW("wrong $iAreaId") EndSwitch ; https://www.autoitscript.com/forum/topic/133222-manipulate-system-tray-program-right-click-choose-option/page/2/#comment-1499538 ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return _EW("$oUIAutomation ERR") ;ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return _EW("$oDesktop ERR") ;ConsoleWrite("$oDesktop OK" & @CRLF) ; Get element by handle Local $pElement, $oElement $oUIAutomation.ElementFromHandle($hToolbar, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return _EW("$oElement ERR") ;ConsoleWrite("$oElement OK" & @CRLF) ; Get condition (ControlType = Button) Local $pCondition, $oCondition $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return _EW("$oCondition ERR") ;ConsoleWrite("$oCondition OK" & @CRLF) ; Find all buttons Local $pElementArray, $oElementArray, $iElements $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray) $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oElementArray.Length($iElements) If Not IsObj($oElementArray) Then Return _EW("$oElementArray ERR") ; Get array of buttons Local $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button $UIA_LegacyIAccessibleNamePropertyId Local $sValue, $aPos[4], $aBtnArray[$iElements][2] Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") Local $iChrCnt = StringLen($sSearchString) Local $sHelpTxt, $bMatch = False Local $aExtract, $aResult For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $sValue) $aElements[$i].CurrentBoundingRectangle($tRect) $aPos[0] = $tRect.Left $aPos[1] = $tRect.Top $aPos[2] = $tRect.Right $aPos[3] = $tRect.Bottom $aBtnArray[$i][0] = $sValue $aBtnArray[$i][1] = $aPos $sHelpTxt &= $i & ") " & $aBtnArray[$i][0] & @CRLF If StringLeft($aBtnArray[$i][0], $iChrCnt) = $sSearchString Then $aExtract = _ArrayExtract($aBtnArray, $i, $i) $bMatch = True $sHelpTxt = "" ExitLoop EndIf Next $aResult = ($bMatch ? $aExtract : $aBtnArray) ; only if $sSearchString not match and <> "@No@" If $sSearchString <> "@No@" Then ConsoleWrite($sHelpTxt) Local $aMpos, $iAdjust Switch $iActionId Case 1 ;Get Return $aResult Case 2, 3, 4 ; 2=$MOUSE_CLICK_LEFT ; 3=$MOUSE_CLICK_RIGHT ; 4=$MOUSE_DBL_CLICK_LEFT ; only if $sSearchString match If UBound($aResult) = 1 Then Local $iClick = ($iActionId = 4 ? 2 : 1) Local $iButton = ($iActionId = 3 ? $MOUSE_CLICK_RIGHT : $MOUSE_CLICK_LEFT) $aPos = $aResult[0][1] ;ConsoleWrite("$aPos =" & $aPos[0] & ", " & $aPos[1] & ", " & $aPos[2] & ", " & $aPos[3] & @CRLF) $iAdjust = ($aPos[2] - $aPos[0]) / 2 $aMpos = MouseGetPos() ;Bakup mouse position If $iAreaId = 3 Then ControlClick($hWndTray, "", $hOverflowButton) ;fist click the Overflow Button MouseClick($iButton, $aPos[0] + $iAdjust, $aPos[1] + $iAdjust, $iClick, 1) If $sOption Then WinActivate($hWndTray) Opt("SendKeyDownDelay", 50) ;you may need to raise Opt("SendKeyDelay", 50) ;you may need to raise Send($sOption) Opt("SendKeyDelay", 5) ;5 milliseconds - Default Opt("SendKeyDownDelay", 5) ;5 milliseconds - Default Send("{ESC}") EndIf MouseMove($aMpos[0], $aMpos[1], 1) ;restore mouse position Return $aResult EndIf Case 5 ; 5=Click&Drag ; only if $sSearchString match If UBound($aResult) = 1 Then $aPos = $aResult[0][1] ;ConsoleWrite("$aPos =" & $aPos[0] & ", " & $aPos[1] & ", " & $aPos[2] & ", " & $aPos[3] & @CRLF) $iAdjust = ($aPos[2] - $aPos[0]) / 2 Local $iBtnWidth = $aPos[2] - $aPos[0] Local $iX2 Local $aOption = StringSplit($sOption, ":") If $aOption[0] = 2 Then If $aOption[1] = "X" Then $iX2 = Int($aOption[2]) ConsoleWrite("$iX2=" & $iX2 & @CRLF) ElseIf $aOption[1] = "Index" Then Local $aIdx = $iAreaId = 1 ? _TaskBar(1, "@No@") : _TaskBar(2, "@No@") $aOption[2] = Int($aOption[2]) If $aOption[2] > UBound($aIdx) - 1 Then Return _EW("wrong Click&Drag $sOption Index:ERR") Local $a = $aIdx[$aOption[2]][1] $iX2 = $a[0] Else Return _EW("wrong Click&Drag $sOption") EndIf Else $sOption = Int($sOption) $iX2 = $aPos[0] + $iAdjust + $iBtnWidth * $sOption EndIf If $sOption = "OverflowButton" Then ; RunningAppsArea not suporting If $iAreaId = 1 Then Return _EW("wrong Click&Drag $sOption, RunningAppsArea not suporting OverflowButton") Local $aCtrlPos = ControlGetPos($hWndTray, "", $hOverflowButton) ;Drag Position = OverflowButton $iX2 = $aCtrlPos[0] + $aCtrlPos[2] / 2 EndIf $aMpos = MouseGetPos() ;Bakup mouse position ; if OverflowNotifyArea fist click the Overflow Button If $iAreaId = 3 Then ControlClick($hWndTray, "", $hOverflowButton) MouseClickDrag($MOUSE_CLICK_LEFT, $aPos[0] + $iAdjust, $aPos[1] + $iAdjust, $iX2, @DesktopHeight - $iAdjust, 1) WinActivate($hWndTray) Send("{ESC}") MouseMove($aMpos[0], $aMpos[1], 1) ;restore mouse position Return $aResult EndIf Case Else Return _EW("wrong $iActionId") EndSwitch ;_ArrayDisplay($aBtnArray) EndFunc ;==>_TaskBar ;-------------------------------------------------------------------------------------------------------------------------------- Func IsMouseOverRect($aRect) If Not IsArray($aRect) Then Return _EW("Not array found") Local $Width = $aRect[2] - $aRect[0] Local $Height = $aRect[3] - $aRect[1] $aRect[2] = $Width $aRect[3] = $Height ;$aRect[0]=X ;$aRect[1]=Y ;$aRect[2]=Width ;$aRect[3]=Height Local $aMpos = MouseGetPos() If $aMpos[0] > $aRect[0] And $aMpos[1] > $aRect[1] And $aMpos[0] < $aRect[0] + $aRect[2] And $aMpos[1] < $aRect[1] + $aRect[3] Then Return True EndIf Return False EndFunc ;==>IsMouseOverRect ;-------------------------------------------------------------------------------------------------------------------------------- Func _EW($sString, $iLine = @ScriptLineNumber) ConsoleWrite("! (" & $iLine & ") " & $sString & @CRLF) EndFunc ;==>_EW ;-------------------------------------------------------------------------------------------------------------------------------- And while we're on the subject of TaskBar, here's another related one ;---------------------------------------------------------------------------------------- ; Title...........: ShellTrayRefresh.au3 ; Description.....: Refreshes ShellTray to remove leftover zombie icons ; AutoIt Version..: 3.3.16.1 Author: ioa747 ; Note............: Testet in Win10 22H2 ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/25/#comment-1529091 ;---------------------------------------------------------------------------------------- Func ShellTrayRefresh() Local $aStartPos = MouseGetPos() Local $hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]") Local $hTlb = ControlGetHandle($hTrayWnd, "", "ToolbarWindow323") Local $hBtn = ControlGetHandle($hTrayWnd, "", "Button2") Local $aPos = ControlGetPos($hTrayWnd, "", $hBtn) Local $aTPos = ControlGetPos($hTrayWnd, "", $hTlb) For $i = ($aPos[0] - 1) + ($aPos[2] / 2) To $aPos[0] + $aPos[2] + $aTPos[2] Step $aPos[2] MouseMove($i, @DesktopHeight - 3, 1) ;~ ConsoleWrite("$i=" & $i & @CRLF) ;~ Sleep(10) Next MouseMove($aStartPos[0], $aStartPos[1], 1) EndFunc ;==>ShellTrayRefresh as well as the link ITaskbarList4 interface Please, every comment is appreciated! leave your comments and experiences here! Thank you very much
    1 point
  3. Update: Problem was with Kerberos authentication breaking sso. RunAs is working like a charm with below. Func SetupEdge() _WD_Option('Driver', 'msedgedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--debug --log-path="' & @appDataDir & '\msedge.log"') RunAs($TargetUsername, $TargetDomain, $TargetPassword, 2, $DriverPath, "", @SW_HIDE) ; As advised by DanP2 _WD_Option('driverdetect', true) ; Run the website in application mode Local $sURL = "https://" & $TargetAddress Local $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": [ "start-maximized" , "--app=' & $sURL & '"], "binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe", "excludeSwitches": [ "enable-automation"]}}}}' ;Local $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args": [ "start-maximized", "user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Microsoft\\Edge\\User Data\\", "profile-directory=Default"], "excludeSwitches": [ "enable-automation"]}}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Return $sSession EndFunc Thanks @Danp2 Regards
    1 point
  4. [New Version] - 27 Jan 22 New: The GUIScrollbar_Ex UDF now recognises Win-D and taskbar desktop clearance commands and runs the correct minimize/restore code automatically. The previous UDF _Minimize and _Restore commands have been superceded by a single _EventMonitor function which runs in the script idle loop. This is a script-breaking change, but I hope that the additional functionality is worth the small effort it will take to alter your scripts. New UDFs, examples in zip file below. Previous changes: Changelog.txt Are you bemused by scrollbars? > Do you find them too difficult to use? > Then you need the GUIScrollbars_Ex UDF! Just download the zip at the end of the post and run this short script with the UDF in the same folder. No tricky calculations, no complicated functions to master - just easy to use, accurate scrollbars with one command! [size=5]#include <guiconstantsex.au3> #include "GUIScrollbars_Ex.au3" ; Create GUI with red background $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xFF0000, $hGUI) ; Create a 1000x1000 green label GUICtrlCreateLabel("", 0, 0, 1000, 1000) GUICtrlSetBkColor(-1, 0x00FF00) GUISetState() ; Generate scrollbars - Yes, this is all you need to do!!!!!!!!!!!!!!!!!!!! _GUIScrollbars_Generate($hGUI, 1000, 1000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd[/size] Try it today and see how easy it is! I have been trying for some time to understand how scrollbars work and how to get them closely to match the area I want to display. After much research and headscratching I have come up with 2 UDFs which I hope will be of use to others. Apologies for the length of this post, but scrollbars are complex beasts and as I did this mainly for the less experienced user I want to make sure that they understand what is going on. The 2 UDFs are: GUIScrollbars_Ex.au3 - This gives you scrollbars sized to your GUI in one simple command - with no other includes or commands needed. The UDF is designed for those who would not normally use scrollbars because the whole process looks too complicated. It also includes a command to enable you to scroll page by page, thus making it easy to scroll to anywhere on the GUI with only simple calulations based on the values you used to create the GUIs. [New] Ability to have recalculated scrollbars on resizeable GUIs. GUIScrollbars_Size.au3 - This calculates the Page and Max numbers for the user to feed into the _GUIScrollbar_SetScrollInfoPage/Max commands. The UDF is aimed at the more experienced user and is particularly useful when you have a GUI with a dynamic scroll size (i.e. adding or subtracting controls to the scrollable area as the script runs). First, a short tutorial for those who are interested in how the scrollbars affect your GUI and what it is that the UDFs calculate: All the files mentioned here are in a downloadable zip file at the end of the post. GUIScrollbars_Size.au3 As mentioned previously, the GUIScrollbars_Size.au3 UDF is aimed at the more experienced user who wants to use the full range of _GUIScrollbar comands, but would like a quick way of getting the required Page and Max values. It uses no other include files so you will need to include GUIScrollbars.au3 yourself, as well as the necessary GUIRegisterMsg and procedures for WM_VSCROLL and WM_HSCROLL. The syntax is simple - the size of the scrollable GUI and either the handle of the GUI you have created to hold the scrollbars or the size of the one you are going to create. It returns a 6-element array including the Page and Max values for the scrollbars and factors to compensate for the "shrinkage" of the GUI if you had already drawn some controls and wished to add others. Of interest, the returned Max value is biased not to clip the edges of the GUI - reducing it by 1 makes a tighter fit but can lead to some clipping. (If that does not make sense, please see the tutorial above for more details) The Size_Example_1 script to show the UDF in action - the "Pass Size" button shows the effect of creating the scrollbars BEFORE the controls, the "Pass Handle" button shows what happens if the scrollbars are created AFTER the controls. If you do not understand why there is a difference - go and read the tutorial above ! You will need to have the GUIScrollbar_Size.au3 UDF in the same folder. Where this UDF really helps is if you have a scrollable GUI of variable size - if the number of controls varies with user selections for example. All you need to do is to rerun the UDF with the new size of the scrollable GUI and it produces a new Max value for you to use. The Size_Example_2 script shows how the function enables you to dynamically size your scrollbars depending on the number of controls required. As before it requires the GUIScrollbar_Size.au3 UDF in the same folder. -------- Now the "simple" GUIScrollbars_Ex.au3 (which is actually the more complex internally as you would expect). This UDF is intended to be the single point of call for creating scrollbars on a GUI - it will automatically add the GUIScrollbars UDF and the WM_VSCROLL and WM_HSCROLL GUIRegisterMsg commands and procedures to your script - so you need no commands other than those within the UDF itself. These commands are _GUIScrollbars_Generate and _GUIScrollbars_Scroll_Page. As you might expect, _GUIScrollbars_Generate generates scrollbars for your GUI. It is usually called AFTER you have added all the controls and all you need to use it is the GUI handle and the size of the underlying GUI you want to scroll. If you so wish, you can also decide to generate the scrollbars BEFORE the controls on the scrollable GUI, and you can choose if you want to risk not quite reaching the edge of the GUI when the scrollbars are at the maximum position. So a basic call could be as simple as: _GUIScrollbars_Generate ($hGUI, 1000, 1000) which would put scrollbars on the $hGUI window allowing a 1000x1000 underlying GUI to be displayed. _GUIScrollbars_Scroll_Page lets you scroll a page at a time. If your GUI was 200 pixels wide, you would have 1000/200 = 5 pages to scroll before reaching the edge - no need to know what the actual Page and Max values are, just use this simple division based on the number you use to draw the GUIs. So: _GUIScrollbars_Scroll_Page ($hGUI, 3) would scroll to the third page - it would display the area between 400 and 600 pixels of the full 1000 pixel width. If you ask for a page over the maximum available, you just scroll to the maximum position - asking for page 1 resets you to the origin. Ex_Example_1 shows the UDF working. You can decide whether to have both or just one scrollbar, whether to create the scrollbars before or after the controls, and whether you want the maximum scroll to be tight to the edge or leave a border. Just select the options you want - the script selects a random width and height for both the scrollbar GUI and the underlying GUI - and press the "Scroll" button to show a single page scroll down and/or right followed by a scroll to the bottom right corner of the GUI. There are labels to let you see the size of the GUI and the accuracy of the page scrolls (please read the tutorial above to understand why these are almost certainly inaccurate). The script requires the GUIScrollbars_Ex.au3 UDF in the same folder. Ex_Example_2 is a really simple example to show how easy generating scrollbars can now become! As you can see - no other includes, no GUIRegisterMsg commands, no WM_H/VSCROLL procedure functions. Just accurate scrolling and proportional thumb sizes. Ex_Example_3 shows the automatic calculation of control positions. Ex_Example_4 shows how to initiate the cursor keys to scroll the GUI as well. [New] Ex_Example_5 shows how to use the new _GUIScrollbarsEx_Resizer function. I hope these 2 UDFs are useful to AutoIt users - I certainly find them so. Here is a zip file with the UDFs and examples: Scrollbars.zip My grateful thanks to the authors of the GUIScrollbars and WinAPI UDFs for their code, some of which I have plundered. And as always I welcome constructive criticism and/or effusive congratulations. M23
    1 point
  5. Nine

    Date Time Range

    What @jchd means is : what's the difference between 16.5 (hr = 16 and mn = 05) and 16.50 (hr = 15 and mn = 50) from your example above ? None. In your script it is interpreted the same way. The issue is that you convert the string (@MIN) into an integer before you concatenate the whole thing into a string. Why? Since the end result is a string. But then your switch use a float (which means that your string is reconverted into a number), so both 16:05 and 16:50 are identical. Local $sTime = int("16") & "." & int("05") ; hr = 16 and mn = 05 Switch $sTime Case 15 to 16.5 ConsoleWrite("bw 15 - 16.5" & @CRLF) EndSwitch Local $sTime = int("16") & "." & int("50") ; hr = 16 and mn = 50 Switch $sTime Case 15 to 16.5 ConsoleWrite("bw 15 - 16.5" & @CRLF) EndSwitch To correctly use your approach, you should have done this : Local $nTime = Number(@HOUR & "." & @MIN) ; my current time is 10:20 ConsoleWrite($nTime & @CRLF) Switch $nTime Case 10 to 10.2 ConsoleWrite("bw 10 - 10.2" & @CRLF) EndSwitch
    1 point
  6. Here, let me then: #include <WinApi.au3> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType) Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _ "hwnd", $hWnd, _ "wstr", $sText, _ "wstr", StringReplace($sTitle, "AutoIt", @ScriptName), _ "uint", $iType) If @error Or Not $aCall[0] Then Return 0 Return $aCall[0] EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Let's try it ; Usual message box MsgBox(0, 'Test', 'Some text') ; Cause error that would say some AutoIt shit happened, but now it wouldn't say "AutoIt" DllStructCreate("byte[123456789097]") ; The End ; The magic is down below Func AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "") Local Static $pImportDirectory, $hInstance Local Const $IMAGE_DIRECTORY_ENTRY_IMPORT = 1 If Not $pImportDirectory Then $hInstance = _WinAPI_GetModuleHandle(0) $pImportDirectory = ImageDirectoryEntryToData($hInstance, $IMAGE_DIRECTORY_ENTRY_IMPORT) If @error Then Return SetError(1, 0, 0) EndIf Local $iIsInt = IsInt($vFunctionName) Local $iRestore = Not IsString($vNewFunction) Local $tIMAGE_IMPORT_MODULE_DIRECTORY Local $pDirectoryOffset = $pImportDirectory Local $tModuleName Local $iInitialOffset, $iInitialOffset2 Local $iOffset2 Local $tBufferOffset2, $iBufferOffset2 Local $tBuffer, $tFunctionOffset, $pOld, $fMatch, $pModuleName, $pFuncName Local Const $PAGE_READWRITE = 0x04 While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pDirectoryOffset) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName") $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $pModuleName) If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset2 = 0 While 1 $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) If Not $iBufferOffset2 Then ExitLoop If $iIsInt Then If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True; wanted function Else $pFuncName = $hInstance + $iBufferOffset2 + 2 ; 2 is size od "word", see line below... $tBuffer = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2) If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True; wanted function EndIf If $fMatch Then $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2) VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE) If @error Then Return SetError(3, 0, 0) $pOld = DllStructGetData($tFunctionOffset, 1) If $iRestore Then DllStructSetData($tFunctionOffset, 1, $vNewFunction) Else DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) EndIf Return $pOld EndIf $iOffset2 += DllStructGetSize($tBufferOffset2) WEnd ExitLoop EndIf $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return SetError(4, 0, 0) EndFunc Func VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc Func ImageDirectoryEntryToData($hInstance, $iDirectoryEntry) ; Get pointer to data Local $pPointer = $hInstance ; Start processing passed binary data. 'Reading' PE format follows. Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _ "word BytesOnLastPage;" & _ "word Pages;" & _ "word Relocations;" & _ "word SizeofHeader;" & _ "word MinimumExtra;" & _ "word MaximumExtra;" & _ "word SS;" & _ "word SP;" & _ "word Checksum;" & _ "word IP;" & _ "word CS;" & _ "word Relocation;" & _ "word Overlay;" & _ "char Reserved[8];" & _ "word OEMIdentifier;" & _ "word OEMInformation;" & _ "char Reserved2[20];" & _ "dword AddressOfNewExeHeader", _ $pPointer) Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic") ; Check if it's valid format If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know. ; Move pointer $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header ; In place of IMAGE_NT_SIGNATURE structure Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer) ; Check signature If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword. EndIf ; Move pointer $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure ; In place of IMAGE_FILE_HEADER structure ; Move pointer $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure ; Determine the type Local $tMagic = DllStructCreate("word Magic;", $pPointer) Local $iMagic = DllStructGetData($tMagic, 1) Local $tIMAGE_OPTIONAL_HEADER If $iMagic = 267 Then ; x86 version ; Move pointer $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER ElseIf $iMagic = 523 Then ; x64 version ; Move pointer $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER Else Return SetError(3, 0, 0) ; unsupported module type EndIf ; Validate input by checking available number of structures that are in the module Local Const $IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16 ; predefined value that PE modules always use (AutoIt certainly) If $iDirectoryEntry > $IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1 Then Return SetError(4, 0, 0) ; invalid input ; Calculate the offset to wanted entry (every entry is 8 bytes) $pPointer += 8 * $iDirectoryEntry ; At place of correst directory entry Local $tIMAGE_DIRECTORY_ENTRY = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddress = DllStructGetData($tIMAGE_DIRECTORY_ENTRY, "VirtualAddress") If $pAddress = 0 Then Return SetError(5, 0, 0) ; invalid input ; $pAddress is RVA, add it to base address Return $hInstance + $pAddress EndFuncedit: because this is better than before.
    1 point
×
×
  • Create New...