Leaderboard
Popular Content
Showing content with the highest reputation on 07/23/2020 in all areas
-
This is an update of the old Automating Windows Explorer example. The update includes Desktop automation. However, Windows XP code has been removed. ThreadsOther threads related to File/Windows Explorer: Implementing Windows Explorer right pane Implementing Windows Explorer address bar Enumerating and Browsing the Desktop Some of these threads are very old. I'm considering updating some of the examples: Remove Windows XP code. Implement some of the code in other ways. Enumerating and Browsing the Desktop is important to me personally because it was the first time I used the ObjCreateInterface() function. The first version of the example was based on _AutoItObject_WrapperCreate() from the AutoItObject UDF. Then I was told that you can use ObjCreateInterface() instead. Of course I had to try. Automating File/Windows Explorer and DesktopAutomating File/Windows Explorer The old example contains a description of the techniques for automating File/Windows Explorer. The techniques are based on COM interfaces. Initially, it's about getting an IShellBrowser interface based on a File/Windows Explorer window handle. An IDispatch interface for the window is important for creating the IShellBrowser interface. Through the IShellBrowser interface, you can generate a large number of interfaces that can be used to implement the automation functions. Automating DesktopBilgus figured out how to get an IDispatch interface for the Desktop in this post: $oIShellWindows.FindWindowSW( Null, Null, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch ) This is the part of the old code in the GetIShellBrowser() function that needs to be updated to include the Desktop: ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows - 1 $oIShellWindows.Item( $i, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next And here the code to include the Desktop is added: ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch, $hRes Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows $hRes = $i < $iWindows ? $oIShellWindows.Item( $i, $pIDispatch ) _ : $oIShellWindows.FindWindowSW( Null, Null, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next The For loop runs an extra round if a File/Explorer Window has not been identified. In this last loop, the FindWindowSW() method returns a window corresponding to the Desktop. Here, the method always returns the Program Manager window. a consequence of this implementation is that if you specify a non-existent window as a parameter to the GetIShellBrowser() function, then the function will return the Program Manager window. Thus, the Program Manager window is the default window for the function. The IDispatch interface is the important thing in terms of automating the Desktop. Then all the functions used in connection with a File/Windows Explorer window can also be used in connection with the Desktop. Except for a few functions that are not relevant for the Desktop. Functions The automation functions are coded in FileExplorer.au3. The functions are implemented using a number of Shell API functions and Shell COM interfaces coded in ShellFunctions.au3 and ShellInterfaces.au3. The old example contains a list of implemented functions. New functions GetSortColumns() GetSortColumnsEx() SetSortColumns() Examples The 7z-file contains examples for automating the Desktop and a File/Windows Explorer window. These are the same examples as in this post. Note that the examples GetFiles.au3 and GetFolders.au3 also show how to make a list of selected files and folders. Note that the GetSetIconView.au3 example can change the order of icons on the Desktop. If you don't want this, run this example only in a File/Windows Explorer window. The GUI application that was used to demonstrate the features in the old version is not included. The small examples seems to be much more useful. This post contains new examples. In both the old and the new post, the examples are shown for a File/Windows Explorer window. But the 7z-file contains similar examples for the Desktop. Forum examplesThis is a list of the most interesting examples in the old thread: The original collection of small examples Automate a file search with UI Automation code. The question that led to this answer was asked in a slightly earlier post. Execute a function on a double-click in empty space of the listview. Based on UI Automation code. Here the question was asked somewhat earlier. UI Automation code to make a selected item visible by scrolling the listview up or down 7z-fileThe 7z-file contains source code for the UDF and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. FileExplorerAndDesktop.7z1 point
-
How to start autoit script from VSCode?
Earthshine reacted to genius257 for a topic
I personally use the damien.autoit extension and have no problem. Have you verified that the AutoIt3Wrapper.au3 file exists at the location? Edit: If no, then try installing this: https://www.autoitscript.com/site/autoit-script-editor/downloads/1 point -
Automating File/Windows Explorer and Desktop
Earthshine reacted to LarsJ for a topic
GetSortColumns()Added a new function to show which column(s) a File/Windows Explorer or Desktop view is sorted by: Func GetSortColumns() Local $iColumns ; Number of sort columns $oIFolderView2.GetSortColumnCount( $iColumns ) ; Get sort columns Local $tagSORTCOLUMNS For $i = 0 To $iColumns - 1 $tagSORTCOLUMNS &= $tagSORTCOLUMN & ";" Next Local $tSortColumns = DllStructCreate( $tagSORTCOLUMNS ) $oIFolderView2.GetSortColumns( $tSortColumns, $iColumns ) ; Get data from structure Local $tSC, $aSortColumns[2*$iColumns][2] For $i = 0 To $iColumns - 1 $aSortColumns[2*$i+0][0] = "Sort" $aSortColumns[2*$i+1][0] = "Column" $tSC = DllStructCreate( $tagSORTCOLUMN, DllStructGetPtr( $tSortColumns ) + $i * DllStructGetSize( $tSortColumns ) ) $aSortColumns[2*$i+0][1] = DllStructGetData( $tSC, "sort" ) PSGetNameFromPropertyKey( DllStructGetPtr( $tSC ), $aSortColumns[2*$i+1][1] ) If @error Then PSStringFromPropertyKey( DllStructGetPtr( $tSC ), $aSortColumns[2*$i+1][1] ) Next ; Return sort columns Return $aSortColumns EndFunc Because the information is extracted from PropertyKeys, column names are displayed this way: Name -> System.ItemNameDisplay Date modified -> System.DateModified Type -> System.ItemTypeText Size -> System.Size When I sort files by Type in a Windows Explorer window, I get this information about the sort columns: Sort -> -1 Column -> System.ItemTypeText Sort -> 0 Column -> {EB4F9DAB-0000-0000-91B9-413D76000090} 0 There are two sort columns. The first is the Type column, which is sorted in descending order. The other doesn't immediately provide any recognizable information. But it's probably used by the internal Microsoft code. Two new examples. One for the Desktop and one for an Explorer window. Note that the Desktop example on Windows 10 simply shows an empty ArrayDisplay window. This is because the Name column for the Desktop is not provided with a sort. So $iColumns in the code box above gets the value zero. And thus $aSortColumns becomes an empty array. Probably there is no sorting for the other columns either (the columns can be seen in Details view). Sorting for the Name column can be set with the code in the next post. And then the sort is displayed in the ArrayDisplay window. Note that setting a sort for the Name column means that the icons on the Desktop are placed in a different order.1 point -
ScriptControl is not an Embeddable ActiveX Control like Windows Media Player. Saludos1 point
-
#include <Misc.au3> #include <WindowsConstants.au3> #include <guiconstantsEx.au3> #include <GuiEdit.au3> HotKeySet("^1", "search") $zoek = "" ; if its going to be a string, its good practice to declare it as a string Global $sIni = @ScriptDir & "\antwoorden.ini" While 1 Sleep(1) WEnd Func _test() Local $sAnswer = "" $sAnswer = IniRead($sIni, "answers", $zoek, "Sorry No answer available") If StringInStr($sAnswer,"<enter>") Then $aAnswer = StringSplit($sAnswer,"<enter>",1) ; 1 = entire delimiter string is needed to mark the split $sAnswer = "" For $i = 1 To $aAnswer[0] $sAnswer &= $aAnswer[$i] & @CR Next EndIf _Sendex ($sAnswer) $zoek = "" ;Reset string EndFunc ;==>_test Func search() $zoek &= InputGui("Test input", "Please enter a search term:" & @CRLF & "Available terms:" & @CRLF & @CRLF, 180, 130 ) _test() EndFunc ;==>search Func _SendEx($ss) Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") If TimerDiff($iT) > 2000 Then MsgBox(262144, "Warning", "Shift, Ctrl and Alt keys need to be released to proceed!") $iT = TimerInit() ; reset the timer EndIf WEnd Send($ss) $zoek = "" ;Reset string EndFunc ;==>_SendEx Func InputGui($titletxt = "", $TextMSG = "", $w = 300, $h = 120) ;Modified source from https://www.autoitscript.com/forum/topic/90035-check-for-valid-file-name-while-entering-text/ ;by dan_555 ;Cancel or X will always return an empty string and the @error will be set to 1 ; Invalid chars are: ['<', '>', '|', '"', '\', '/', ':', '*', '?'] If $w < 85 Then $w = 85 If $h < 85 Then $h = 85 Local $MyGui = GUICreate($titletxt, $w, $h, -1, -1, $WS_POPUP + $WS_CAPTION) Local $Edit = GUICtrlCreateEdit($TextMSG, 4, 4, $w - 8, $h - 55, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $WS_VSCROLL)) Local $input = GUICtrlCreateInput("", 4, $h - 50, $w - 8, 20, $ES_WANTRETURN) Local $buttonOK = GUICtrlCreateButton("OK", 4, $h - 25, 35, 20) Local $buttonCA = GUICtrlCreateButton("Cancel", $w - 45, $h - 25, 40, 20) GUISetState(@SW_SHOW) Local $final, $tmp, $itxt, $itxtold, $Err = 0 Local $WinPos While 1 $WinPos = WinGetPos($MyGui) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $buttonCA $Err = 1 ExitLoop Case $msg = $buttonOK Or _IsPressed("0D") ExitLoop EndSelect $itxt = GUICtrlRead($input) If $itxt <> $itxtold Then $itxtold = $itxt $tmp = ReadIniAnswers($itxt) _GUICtrlEdit_BeginUpdate($Edit) GUICtrlSetData($Edit, "", 1) GUICtrlSetData($Edit, $TextMSG & $tmp) _GUICtrlEdit_EndUpdate($Edit) EndIf Sleep(10) WEnd If $Err = 0 Then $final = GUICtrlRead($input) GUIDelete($MyGui) Return $final Else GUIDelete($MyGui) SetError(1) Return "" EndIf EndFunc ;==>InputGui Func ReadIniAnswers($text) Local $array = IniReadSection($sIni, "answers") Local $list = "" Local $x, $y For $x = 1 To $array[0][0] For $y = StringLen($text) To 1 Step -1 If StringLeft($array[$x][0], $y) = $text Then $list = $list & $array[$x][0] & @CRLF ExitLoop EndIf Next Next Return $list EndFunc ;==>ReadIniAnswers Atm the gui is not responding to the enter key, but i'm sure it can be done so. Done.1 point
-
Fixed, sorry, have no idea how that happened.1 point
-
something like this ? : #include <WindowsConstants.au3> #include <guiconstantsEx.au3> #include <GuiEdit.au3> Global $sIni = @ScriptDir & "\antwoorden.ini" ConsoleWrite(InputGui("Test input", "Please enter a search term:" & @CRLF & "Available terms:" & @CRLF & @CRLF, 180, 130 )) Func InputGui($titletxt = "", $TextMSG = "", $w = 300, $h = 120) ;Modified source from https://www.autoitscript.com/forum/topic/90035-check-for-valid-file-name-while-entering-text/ ;by dan_555 ;Cancel or X will always return an empty string and the @error will be set to 1 ; Invalid chars are: ['<', '>', '|', '"', '\', '/', ':', '*', '?'] If $w < 85 Then $w = 85 If $h < 85 Then $h = 85 Local $MyGui = GUICreate($titletxt, $w, $h, -1, -1, $WS_POPUP + $WS_CAPTION) Local $Edit = GUICtrlCreateEdit($TextMSG, 4, 4, $w - 8, $h - 55, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $WS_VSCROLL)) Local $input = GUICtrlCreateInput("", 4, $h - 50, $w - 8, 20, $ES_WANTRETURN) Local $buttonOK = GUICtrlCreateButton("OK", 4, $h - 25, 35, 20) Local $buttonCA = GUICtrlCreateButton("Cancel", $w - 45, $h - 25, 40, 20) GUISetState(@SW_SHOW) Local $final, $tmp, $itxt, $itxtold, $Err = 0 Local $WinPos While 1 $WinPos = WinGetPos($MyGui) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $buttonCA $Err = 1 ExitLoop Case $msg = $buttonOK ExitLoop EndSelect $itxt = GUICtrlRead($input) If $itxt <> $itxtold Then $itxtold = $itxt $tmp = ReadIniAnswers($itxt) _GUICtrlEdit_BeginUpdate($Edit) GUICtrlSetData($Edit, "", 1) GUICtrlSetData($Edit, $TextMSG & $tmp) _GUICtrlEdit_EndUpdate($Edit) EndIf Sleep(10) WEnd If $Err = 0 Then $final = GUICtrlRead($input) GUIDelete($MyGui) Return $final Else GUIDelete($MyGui) SetError(1) Return "" EndIf EndFunc ;==>InputGui Func ReadIniAnswers($text) Local $array = IniReadSection($sIni, "answers") Local $list = "" Local $x, $y For $x = 1 To $array[0][0] For $y = StringLen($text) To 1 Step -1 If StringLeft($array[$x][0], $y) = $text Then $list = $list & $array[$x][0] & @CRLF ExitLoop EndIf Next Next Return $list EndFunc ;==>ReadIniAnswers1 point
-
I am not going to try to guess what the problem is. Either show your code or a small script that reproduces the issue.1 point
-
Have you tried URL encoding your URL or at least the values of the parameters that you are passing? The topic below is just one of many discussions that provides a solution. The example below uses the functions in that topic with your URL. #include <Constants.au3> Global $gsUnicodeValue = "http://domain.ir/api.php?ApiKey=96307850859&Product=Whatever&F_Name=رضا&L_Name=یوسفی" Global $gsEncodedValue = _UnicodeURLEncode($gsUnicodeValue) Global $gsDecodedValue = _UnicodeURLDecode($gsEncodedValue) MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, _ "INFO", _ "Unicode value: " & $gsUnicodeValue & @CRLF & @CRLF & _ "Encoded value: " & $gsEncodedValue & @CRLF & @CRLF & _ "Decoded value: " & $gsDecodedValue _ ) ;=============================================================================== ; _UnicodeURLEncode() ; Description: : Encodes an unicode string to be URL-friendly ; Parameter(s): : $UnicodeURL - The Unicode String to Encode ; Return Value(s): : The URL encoded string ; Author(s): : Dhilip89 ; Note(s): : - ; ;=============================================================================== Func _UnicodeURLEncode($UnicodeURL) $UnicodeBinary = StringToBinary ($UnicodeURL, 4) $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) $UnicodeBinaryLength = StringLen($UnicodeBinary2) Local $EncodedString For $i = 1 To $UnicodeBinaryLength Step 2 $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar) Else $EncodedString &= '%' & $UnicodeBinaryChar EndIf Next Return $EncodedString EndFunc ;==>_UnicodeURLEncode ;=============================================================================== ; _UnicodeURLDecode() ; Description: : Tranlates a URL-friendly string to a normal string ; Parameter(s): : $toDecode - The URL-friendly string to decode ; Return Value(s): : The URL decoded string ; Author(s): : nfwu, Dhilip89 ; Note(s): : Modified from _URLDecode() that's only support non-unicode. ; ;=============================================================================== Func _UnicodeURLDecode($toDecode) Local $strChar = "", $iOne, $iTwo Local $aryHex = StringSplit($toDecode, "") For $i = 1 To $aryHex[0] If $aryHex[$i] = "%" Then $i = $i + 1 $iOne = $aryHex[$i] $i = $i + 1 $iTwo = $aryHex[$i] $strChar = $strChar & Chr(Dec($iOne & $iTwo)) Else $strChar = $strChar & $aryHex[$i] EndIf Next $Process = StringToBinary (StringReplace($strChar, "+", " ")) $DecodedString = BinaryToString ($Process, 4) Return $DecodedString EndFunc ;==>_UnicodeURLDecode1 point