Popular Post scintilla4evr Posted August 9, 2016 Popular Post Share Posted August 9, 2016 (edited) For some time I was wondering how to execute AutoIt code from a web browser. I made some solutions using IE.au3, but that's only one browser. Is there a way to execute AutoIt from ANY browser? There is one - custom protocols. So, I looked how to add one, and here it is - running AutoIt from any web browser. AutoIt Protocol Example (run install.au3 before!): 2+2 in a MsgBox Edit: you can't use this protocol in posts here, how sad Have fun! Edited August 9, 2016 by scintilla4evr cramaboule, mLipok, robertocm and 4 others 6 1 Just Monika. Spoiler CompileIt - an experimental AutoIt-to-machine code compiler Apps: Power Calculator | AutoItFX | AudioBox | vPaint 4 | Color Book Editor UDFs: Advanced Math UDF | Blender UDF | Motion Graphics UDF | ColorEx UDF | ChakraCore UDF | CUDA UDF Adobe UDFs: Photoshop | ... Examples & Small Scripts: Distorting GDI+ Paths with other Paths | Combining GDI+ Paths with different combine modes | _WinAPI_DwmEnableBlurBehindWindow in Windows 10 | Running AutoIt code from any web browser Link to comment Share on other sites More sharing options...
Dreamfire Posted August 10, 2016 Share Posted August 10, 2016 Awesome solution, this will definitely come in handy! Link to comment Share on other sites More sharing options...
robertocm Posted August 13, 2018 Share Posted August 13, 2018 (edited) I'm finding this very useful, also for working with emails (Thunderbird) For example, an automated report send me a mail, with html code generated like this Local $oStream = ObjCreate("ADODB.Stream") $oStream.Type = 2 ; adTypeText $oStream.Charset = "utf-8" $oStream.LineSeparator = -1 ; adCRLF $oStream.Open ;https://msdn.microsoft.com/en-us/library/ms678072(v=vs.85).aspx ;StreamWriteEnum: 1 adWriteLine $oStream.WriteText("<html>", 1) $oStream.WriteText("<head>", 1) $oStream.WriteText("<style>", 1) ;.... $oStream.WriteText(".Menu li a:hover:not(.active) {background-color: #ddd;}", 1) $oStream.WriteText("</style>", 1) $oStream.WriteText("</head>", 1) $oStream.WriteText("<body>", 1) $oStream.WriteText("<ul class='Menu' style='list-style-type: none;margin: 0;padding: 0;overflow: hidden;border: 1px solid #e7e7e7;background-color: #f3f3f3;'>", 1) $oStream.WriteText("<li style='float: left;'><a href='autoit:MyScript.a3x|\\MyServe\MyFolderPath\' moz-do-not-send='true' style='display: block;color: white;background-color: #4CAF50;text-align: center;padding: 5px 7px;text-decoration: none;'>Some Folder</a></li>", 1) $oStream.WriteText("<li style='float: left;'><a href='#news' moz-do-not-send='true' style='display: block;color: #666;text-align: center;padding: 5px 7px;text-decoration: none;'>Another link</a></li>", 1) $oStream.WriteText("</ul><br><br>", 1) $oStream.WriteText("</body>", 1) $oStream.WriteText("</html>", 1) $oStream.Position = 0 ;... $sBody = $oStream.ReadText Here is a simplified version of your code: i prefer to allow only execution of pre-saved autoit files handler.au3 expandcollapse popup#pragma compile(AutoItExecuteAllowed, true) ; Required! #pragma compile(FileDescription, "AutoIt Protocol Handler") #pragma compile(FileVersion, 1.1.0.0) #pragma compile(CompanyName, scintilla4evr) #pragma compile(Icon, icon.ico) If @Compiled Then Local $sData = StringTrimLeft($CmdLineRaw, 8) $sData = StringTrimRight($sData, 1) $sData = _URIDecode($sData) ;_RunAU3(".\scripts\AU3_Example.au3", $sData, @ScriptDir, @SW_SHOW, 8) ;in $sData there is a string with this format: AU3_Example.au3|parameter1 'parameter 2' ""parameter 3"" Local $aArray = StringSplit($sData, "|") _RunAU3(".\scripts\" & $aArray[1], $aArray[2], @ScriptDir, @SW_SHOW, 8) EndIf #cs HTTP.au3 made by @Jefrey Repo: http://github.com/jesobreira/HTTP.au3 #ce Func URLDecode($urlText) $urlText = StringReplace($urlText, "+", " ") Local $matches = StringRegExp($urlText, "\%([abcdefABCDEF0-9]{2})", 3) If Not @error Then For $match In $matches $urlText = StringReplace($urlText, "%" & $match, BinaryToString('0x' & $match)) Next EndIf Return $urlText EndFunc ;==>URLDecode ;failed with ñ characters ¿unicode? ;ProgAndy ;https://www.autoitscript.com/forum/topic/95850-url-encoding/?do=findComment&comment=689060 Func _URIDecode($sData) ; Prog@ndy ;Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%") Local $aData = StringSplit($sData,"%") $sData = "" For $i = 2 To $aData[0] $aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2) Next Return BinaryToString(StringToBinary($aData[1],1),4) EndFunc ;guinness ;https://www.autoitscript.com/forum/topic/135203-call-another-script/?do=findComment&comment=943199 Func _RunAU3($sFilePath, $sParamet="", $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0) Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '" "' & $sParamet & '"', $sWorkingDir, $iShowFlag, $iOptFlag) EndFunc ;==>_RunAU3 install.au3 #RequireAdmin ;Add necessary registry values & keys RegWrite("HKCR\autoit", "", "REG_SZ", "URL:AutoIt Protocol") RegWrite("HKCR\autoit", "URL Protocol", "REG_SZ", "") RegWrite("HKCR\autoit\DefaultIcon", "", "REG_SZ", @AutoItExe&",1") RegWrite("HKCR\autoit\shell\open\command", "", "REG_SZ", '"' & @ScriptDir & "\handler.exe" & '" "%1"') Many Thaks! Edited August 16, 2018 by robertocm Changed the url decode function because of 'ñ' characters Link to comment Share on other sites More sharing options...
robertocm Posted August 15, 2018 Share Posted August 15, 2018 (edited) This is only an 'experiment', just for curiosity: using the custom protocol to run AutoIt code from excel VBA and excel sheet formula (hyperlink) First the formula example: =HYPERLINK("autoit:MsgBox(0,'2+2',2+2)","Run AutoIt Code") The same but from VBA using ActiveWorkbook.FollowHyperlink: Sub Run_AutoIt_code_from_VBA_FollowHyperlink() Dim sLink As String sLink = "autoit:MsgBox(0,'2+2',2+2)" ActiveWorkbook.FollowHyperlink sLink End Sub Using ShellExecute API function: this does not display the excel links alert message #If VBA7 Then Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr #Else Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long #End If Sub Run_AutoIt_code_from_VBA_ShellExecute_Single_line() Dim sCmd As String sCmd = "autoit:MsgBox(0,'2+2',2+2)" Call ShellExecute(0&, vbNullString, sCmd, vbNullString, vbNullString, vbNormalFocus) End Sub Sub Run_AutoIt_code_from_VBA_ShellExecute_Multi_line() Dim sCmd As String sCmd = "autoit:str-format($str = InputBox('Question', 'What''s your favorite color?')\nIf Not @error Then MsgBox(0, 'Answer', $str))" Call ShellExecute(0&, vbNullString, sCmd, vbNullString, vbNullString, vbNormalFocus) End Sub The excel file with examples: examples_from_excel.xlsm Edited August 15, 2018 by robertocm Link to comment Share on other sites More sharing options...
robertocm Posted August 23, 2018 Share Posted August 23, 2018 (edited) ¿Is it possible to 'receive' the content of an htm form? I mean the content of the html input boxes I'm working with thunderbird html mail For reference: - Beating Thunderbird’s Checkbox Bug (and Targeting Techniques) Quote I noticed that clicking on any form element causes the form to be submitted. If the form has a url within an action attribute, the form is posted to that url. <form id=f2 action="autoit:Some_Name.a3x"> <label for=form-name>Name</label> <input name=form-name id=form-name type=text required><br> <label for=form-email>Email</label> <input name=form-email id=form-email type=email required><br> <label for=form-url>URL</label> <input name=form-url id=form-url type=url><br> <label for=form-comment>Comment</label> <textarea name=form-comment id=form-comment required></textarea><br> <input type=submit> </form> Update: MsgBox(0, "Read Content from html form", StringSplit($CmdLine[1], "?")[2]) found by chance But not possible from thunderbird mail because form element has to be opened like: <form action="#"> This is the form tested <html> <body> <form id=form1 action="autoit:Read_form.au3|dummy"> </form> <label form=form1 for=form-name>Name</label> <input form=form1 type="text" id="text" name="text" value="Some text"><br> <input form=form1 type=submit> <br><br> References:<br> "In HTML5, a number of elements that were previously required to be within a form element<br> (button, fieldset, input, label, select, textarea, etc.)<br> can now be anywhere on the page and associated with a form using a form attribute pointing at the id of its form owner."<br> (sorry i don't have here the author's name)<br> <br> - Justin, Nov 2014 http://freshinbox.com/blog/interactive-tabs-for-email<br> - https://www.emailonacid.com/blog/article/email-development/beating-thunderbirds-checkbox-bug-and-targeting-techniques/<br> </html> </body> Edited August 23, 2018 by robertocm 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