Popular Post trancexx Posted May 14, 2011 Popular Post Share Posted May 14, 2011 (edited) Majority of users of AutoIt language likes it because it's easy to learn and very powerful when it comes to automating some basically very complicated stuff on windows. AutoIt often does it in just one line of code while doing it in other languages would be writing a full book of code.How to use AutoIt with other languages? One way would be to use AutoItX. Dll version of AutoIt. In this case you can access it through COM or exported functions. Downside surely is limited number of available functions and user rights for COM option.Other way is... no wait, there is no other way.But, what If I add some magic salt to the soup? Let's say I use some of the code from (thanks Manadar) and, yes you guessed AutoItObject, and make a simple (the most basic) COM server that exports almost the whole AutoIt functionality to anyone wanting to use it.AutoItObject 1.2.8.0 makes objects published to ROT (running object table) more accessible than ever. Accessing the object is as easy as GetObject(...) in any scripting language and CoGetObject() through Windows API.An example of VBS would be:'Start AutoIt server script first Set oAutoIt = GetObject("AutoIt.Application") ' the magic WS_OVERLAPPEDWINDOW = &H00CF0000 hGui = oAutoIt.Call("GUICreate", "VBS AutoIt GUI test", -1, -1, -1, -1, WS_OVERLAPPEDWINDOW) hButton = oAutoIt.Call("GUICtrlCreateButton", "Click", 100, 100, 100, 30) hButton2 = oAutoIt.Call("GUICtrlCreateButton", "Click me too", 100, 300, 100, 30) oAutoIt.Call "WinSetOnTop", "VBS AutoIt GUI test", "", 1 AW_FADE_IN = &H00080000 oAutoIt.Call "DllCall", "user32.dll", "bool", "AnimateWindow", "hwnd", hGui, "dword", 1000, "dword", AW_FADE_IN oAutoIt.Call "GUISetState" Do Select Case oAutoIt.Call("GUIGetMsg") Case -3 Exit Do Case hButton oAutoIt.Call "MsgBox", 262144+32+3, "Title", "Bzzz bzz bzzzz", 0, hGUI Case hButton2 oAutoIt.Call "Beep", 500, 700 End Select Wscript.Sleep(10) Loop oAutoIt.Call "GUIDelete" If oAutoIt.Call("MsgBox", 4 + 48 + 262144, "?", "Kill server?") = 6 Then oAutoIt.QuitJavascript could be:// Start AutoIt server script first // Let's go... try { oAutoIt = GetObject("AutoIt.Application"); oAutoIt.Call("Beep", 1000, 500) oAutoIt.Call("MsgBox", 64 + 262144, "Hi there!", "Is this something or what?") if (oAutoIt.Call("MsgBox", 4 + 48 + 262144, "?", "Kill server?") == 6) { oAutoIt.Quit; } } catch(err) { WScript.echo("!Ermmm... is server script runing?"); }C#using System; using System.Reflection; using System.Runtime.InteropServices; class Program { static void Main(string[] args) { try { dynamic myAu3Object = Marshal.BindToMoniker("AutoIt.Application"); myAu3Object.Call("ToolTip", "Some cool text"); myAu3Object.Call("Beep", 500, 700); myAu3Object.Call("Sleep", 1000); myAu3Object.Call("ToolTip", ""); if (myAu3Object.Call("MsgBox", 4 + 48 + 262144, "?", "Kill Server?") == 6) { myAu3Object.Quit(); } } catch { System.Console.WriteLine("Something is wrong. Double-check everything."); } } }PowerShell (based on ptrex's example)# Start server script first $oAutoIt = [System.Runtime.InteropServices.Marshal]::BindToMoniker("AutoIt.Application") $oAutoItType = $oAutoIt.GetType() $im = [System.Reflection.BindingFlags]::InvokeMethod # $gp = [System.Reflection.BindingFlags]::GetProperty $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", "Some cool text",600, 300)) $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Beep", 500, 700)) $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Sleep", "2000")) $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", ""))Python (AdmiralAlkex)import win32com.client try: oAutoIt = win32com.client.GetObject("AutoIt.Application") oAutoIt.Call("Tooltip", "Some cool text") oAutoIt.Call("Beep", 500, 700) oAutoIt.Call("Sleep", 3000) oAutoIt.Call("Tooltip", "") if oAutoIt.Call("MsgBox", 4 + 48 + 262144, "?", "Kill Server?") == 6: oAutoIt.Quit except: print ("+Ermmm... is server script running?") #Lets have a green output on this example (SciTE)...and so on.Server script is really minimalistic:expandcollapse popup#include "AutoitObject.au3" Opt("MustDeclareVars", 1) ; Error monitoring Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ;~ ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc ; Initialize AutoItObject _AutoItObject_StartUp() ; Create object Global $oObject = _SomeObject() ; Register it globaly with some identifier Global $sMyCLSID = "AutoIt.Application" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) While 1 Sleep(100) WEnd _QuitObject(0) ; Define object Func _SomeObject() Local $oClassObject = _AutoItObject_Class() $oClassObject.AddMethod("Call", "_Obj_CallAny") $oClassObject.AddMethod("Quit", "_QuitObject") Return $oClassObject.Object EndFunc ;==>_SomeObject Func _Obj_CallAny($oSelf, $sFunc, _ $vParam1 = 0, $vParam2 = 0, $vParam3 = 0, $vParam4 = 0, $vParam5 = 0, $vParam6 = 0, _ $vParam7 = 0, $vParam8 = 0, $vParam9 = 0, $vParam10 = 0, $vParam11 = 0, $vParam12 = 0, _ $vParam13 = 0, $vParam14 = 0, $vParam15 = 0, $vParam16 = 0, $vParam17 = 0, $vParam18 = 0, _ $vParam19 = 0, $vParam20 = 0, $vParam21 = 0, $vParam22 = 0, $vParam23 = 0, $vParam24 = 0, _ $vParam25 = 0, $vParam26 = 0, $vParam27 = 0, $vParam28 = 0, $vParam29 = 0, $vParam30 = 0) Local $sExec = $sFunc & "(" If @NumParams = 3 And IsArray($vParam1) And UBound($vParam1, 0) = 1 Then For $n = 0 To UBound($vParam1) - 1 $sExec &= "$vParam1[" & $n & "]," Next Else If @NumParams = 2 Then $sExec &= ")" Else For $n = 1 To @NumParams - 2 $sExec &= "$vParam" & $n & "," Next EndIf EndIf Local $vRet = Execute(StringTrimRight($sExec, 1) & ")") If IsPtr($vRet) Then Return Number($vRet) For $i = 0 To UBound($vRet) - 1 If IsPtr($vRet[$i]) Then $vRet[$i] = Number($vRet[$i]) Next Return $vRet EndFunc ;==>_Obj_CallAny Func _QuitObject($oSelf) MsgBox(262144 + 64, "Server says...", "bye bye", 3) _AutoItObject_UnregisterObject($hObj) $oObject = 0 Exit EndFunc ;==>_QuitObjectAll packed in ZIP:AccessAutoIt.zipWhat you'll find there is folder named AccessAutoIt. Unzip it somewhere and inside there will be five files: AutoItObject.au3 (1.2.8.0), AutoItServer.au3, Csharp.cs, JS.js and VBS.vbs.Run AutoItServer.au3 and then either vbs or js script or compile Csharp.cs and run resulting executable. I have chosen AutoIt.Application object moniker for no particular reason. Can be anything.Latest AutoItObject, if you want the whole thing, is here.AutoIt on your palm.edit: Added c# example.Don't mind about my usage of other languages. I'm not quite familiar with them. Edited May 20, 2011 by trancexx SEuBo, mLipok, DinFuv and 4 others 6 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 14, 2011 Share Posted May 14, 2011 Amazing! Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
czardas Posted May 14, 2011 Share Posted May 14, 2011 If this is capable of what I think it's capable of, then: Way Hey! operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Andreik Posted May 14, 2011 Share Posted May 14, 2011 Indeed, this is awesome. Good job! When the words fail... music speaks. Link to comment Share on other sites More sharing options...
trancexx Posted May 14, 2011 Author Share Posted May 14, 2011 (edited) If this is capable of what I think it's capable of, then: Way Hey! This reminds me on one episode of Malcolm in the Middle when he's babysitting this old lady with broken arm. She falls asleep at some point and he invites his geeks over knowing she'll be sleeping for few hours. One "tough" geek says something like: "Do you guys think what I think?", they all go "Yeahhhh!!!". ...If you ever see me laughing with no reason, it's probably because I remembered the next scene from that episode. OMG hilarious! It's completely above me. Needless to say, they didn't think what he thought.I've added c# example. First post. Edited May 14, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jvanegmond Posted May 14, 2011 Share Posted May 14, 2011 CoGetObject. The code is beautiful. github.com/jvanegmond Link to comment Share on other sites More sharing options...
trancexx Posted May 14, 2011 Author Share Posted May 14, 2011 CoGetObject. The code is beautiful. Could be reduced to: object myAu3Object = Marshal.BindToMoniker("AutoIt.Application"); ;...Would that be more correct? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JScript Posted May 15, 2011 Share Posted May 15, 2011 wonderful!!! http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
czardas Posted May 15, 2011 Share Posted May 15, 2011 ...If you ever see me laughing with no reason, it's probably because I remembered the next scene from that episode. OMG hilarious! It's completely above me. Needless to say, they didn't think what he thought.Hmm unfortunately I'm not familiar with the episode, so I'll have to imagine what the others were thinking. On the other hand, Access AutoIt may do much more than I think it does. Either way I like the examples. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jvanegmond Posted May 15, 2011 Share Posted May 15, 2011 Could be reduced to: object myAu3Object = Marshal.BindToMoniker("AutoIt.Application"); ;...Would that be more correct? Native .NET calls are preferred over WinAPI / external calls for a number of reasons. Even if it's just a wrapper around an external call. github.com/jvanegmond Link to comment Share on other sites More sharing options...
ptrex Posted May 15, 2011 Share Posted May 15, 2011 (edited) @trancexxThis is great !Now AutoIT has a bi-directional COM approach, which is a new milestone. Very nice implementation indead Here is the Powershell example tested on windows 7 - X64.# No GetObject in Powershell !! # http://technet.microsoft.com/en-us/library/ee176862.aspx cls # AutoIT Object instantition [reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic") $oAutoIt = [Microsoft.VisualBasic.Interaction]::GetObject("AutoIt.Application") $oAutoItType = $oAutoIt.GetType() $im = [reflection.bindingflags]::InvokeMethod $gp = [reflection.bindingflags]::GetProperty $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", "Some cool text",600, 300)) #$oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Beep", 500, 700)) $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Sleep", "2000")) $oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", ""))So the only thing that leaves a black spot on AU3 is that it can't access Powershell or .Net classes.Ps:Forgot to mention save this example as .PS1 file and you can run this on any windows 7 OS natively.Don't need to install any additional software dev. environment.Rgds,ptrex Edited May 16, 2011 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
trancexx Posted May 15, 2011 Author Share Posted May 15, 2011 That's new to me ptrex. I've tested it and works really fine. Thank you. Added to first post, Thanks again. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 15, 2011 Share Posted May 15, 2011 (edited) @trancexxThis is pretty damn awesome! Here's a Python example(needs pywin32)import win32com.client try: oAutoIt = win32com.client.GetObject("AutoIt.Application") oAutoIt.Call("Tooltip", "Some cool text") oAutoIt.Call("Beep", 500, 700) oAutoIt.Call("Sleep", 3000) oAutoIt.Call("Tooltip", "") if oAutoIt.Call("MsgBox", 4 + 48 + 262144, "?", "Kill Server?") == 6: oAutoIt.Quit except: print ("+Ermmm... is server script running?") #Lets have a green output on this example (SciTE)Edit: Updated example to work on both Python 2 and 3 (tested on 2.6.5 and 3.2) Edited May 16, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
monoceres Posted May 16, 2011 Share Posted May 16, 2011 On another matter, is it my shirt that's electric? Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
BillLuvsU Posted May 16, 2011 Share Posted May 16, 2011 50 thumbs up, then some more. You make me wish I had thought of it first every time you post something mate, absolutely fantabulous. [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
ValeryVal Posted May 16, 2011 Share Posted May 16, 2011 Yes, your COMlet (Autolet?) way works very good. and make a simple (the most basic) COM server that exports almost the whole AutoIt functionality to anyone wanting to use it. Have you thoughts about WEB server creation like your AutoItServer.au3? So the only thing that leaves a black spot on AU3 is that it can't access Powershell or .Net classes.You have to build COMlet way (through ROT) from Powershell with help of new AutoIt facility, I think The point of world view Link to comment Share on other sites More sharing options...
Armin Posted May 16, 2011 Share Posted May 16, 2011 (edited) In the scripting language LUA is closed with an error. require("luacom") oAutoIt = luacom.GetObject("AutoIt.Application") print(oAutoIt) Edited May 16, 2011 by Armin Link to comment Share on other sites More sharing options...
Digisoul Posted May 16, 2011 Share Posted May 16, 2011 Excellent work trancexx, Ii have a one question, can we use this approach for IPC ? 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
trancexx Posted May 16, 2011 Author Share Posted May 16, 2011 Excellent work trancexx,Ii have a one question, can we use this approach for IPC ?That goes without saying.Objects have properties. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Digisoul Posted May 17, 2011 Share Posted May 17, 2011 (edited) That goes without saying.Objects have properties.I am new in objects. can you please post a one example. Edited May 17, 2011 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 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