Jump to content
doudou

AU3Automation - export AU3 scripts via COM interfaces

Recommended Posts

doudou

Ever wanted to be able to use functions in your AU3 scripts from WSH, VBasic or other COM capable programming language? Well, now it is possible.

Please meet: AU3Automation library. It consists of two parts, a COM proxy DLL AU3Aut.dll/AU3Aut64.dll and a small UDF AU3Automation.au3 - both are in the attached archive. Extract the DLL somewhere on your computer (<WinDir>system32 would be a good destination but it is up to you), do

regsvr32 AU3Aut.dll

resp. on 64-bit system

regsvr32 AU3Aut64.dll

(or alternatively just run attached AU3AutRegsiter.au3 script) in the directory, where you extracted it, copy then the UDF files in your AutoIt include directory and start writing automation servers in AU3.

Things you can do with AU3Automation

  • Create COM server in your plain or compiled AU3 script, in latter case AutoIt doesn't even need to be installed on the target computer to use the server.
  • Export any user defined function.
  • Export any global variable (some types aren't supported, s. exceptions below).
  • Call exported functions or read/write exported variables from any programming language that supports late binding (i.e. "CreateObject").
  • Read all AutoIt @macros from COM clients. Although some macros appear quite pointless in the client context (like dynamic ones: @error, @NumParams, @ScriptLineNumber) but most of them are pretty handy.
Things you cannot do with AU3Automation

  • Export AutoIt built-in functions. A simple UDF wrapper would be exactly as good.
  • Export DllStruct variables or use them as parameter or return type in exported function. No great loss: most of possible clients won't understand them anyway.
  • Access parameters in exported functions ByRef.
  • Raise a specific COM error from within AU3. This is planned in the future, in the meantime you always can export a readonly variable and save error code or description in it (s. example below).
  • Use objects created with AutoItObject in exported variables or return values of exported functions. This is a pity but maybe one day I can convince the AIO team to add marshalling to their great tool.
  • Make coffee, your wife happy and perform brain surgery.
Things you shouldn't do with AU3Automation

  • Use pointers (not even converted to numbers) in exported variables and return values of exported functions. Because the COM server is started in a separate process it has its own address space and all pointers are invalid - thus useless - from the client's perspective.
  • Block the execution of an exported function for to long (f.i. by displaying a MsgBox without timeout). AU3Aut proxy only waits a certain time span for a call to complete and let the client see failure if the call doesn't return in time. The default timeout is 20000 ms and can be set in the client as the second optional parameter of AU3Aut.Load().
  • Use AU3Aut server in ASP or any other networking server application accessible from behind the firewall, it is just to risky.
  • Manufacture weapons of mass destruction.
Here's one possible application - a VBScript that uses AU3Script to show "Open File" common dialog.

COM server (OpenFileDialog.au3):

#include "AU3Automation.au3"

_AU3Aut_ExportVariable("title", False, "")
_AU3Aut_ExportVariable("initialDir", False, "")
_AU3Aut_ExportVariable("filter", False, "All (*.*)")
_AU3Aut_ExportVariable("options")
_AU3Aut_ExportVariable("defaultName", False, "")
_AU3Aut_ExportVariable("error", True)
_AU3Aut_ExportFunction("Show")
If Not _AU3Aut_Publish() Then Exit -1

_AU3Aut_StayAliveWhileInUse()

Func Show()
Local $result = FileOpenDialog($title, $initialDir, $filter, $options, $defaultName)
$error = @error
Return $result
EndFunc

COM client (OpenFileDialog.vbs):

Set scr = WScript.CreateObject("AU3Aut.Scriptlet")
Set dialog = scr.Load("OpenFileDialog.au3")

dialog.title = "Please Select File"
dialog.filter = "Text Files (*.txt)"
dialog.options = 1 Or 2

path = dialog.Show()

WScript.Echo "OpenFileDialog returned [" & path & "], error was " & dialog.error

Some more usage examples are in the samples archive.

Requirements

  • AutoIt 3.3.4.0 (minimum)
  • AutoItObject 1.0.x (though its core functionality isn't the subject here, it provides OLE tools I was to lazy to write myself :idea: )
  • DDEML 1.5.4 (make sure you have at least this version)
Download

Project Links @ SourceForge

Edited by doudou
  • Like 1

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
ptrex

@doudou

This is the best news I have seen lately in this forum ! :idea:

I get to test it right away.

If I see the time I will provide you a regfree COM dll version.

Where you don't need to register it all the time on each machine.

Thanks for sharing !

rgds

ptrex

Share this post


Link to post
Share on other sites
doudou

This is the best news I have seen lately in this forum ! :idea:

You are exaggerating, my dear. I deeply appreciate your benevolent kindness nonetheless. :)

If I see the time I will provide you a regfree COM dll version.

Where you don't need to register it all the time on each machine.

The proxy has to be registered one way or the other, otherwise the client wouldn't know how to CreateObject("AU3Aut.Scriptlet"). CoCreateInstance() is a pedantic beast.

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
ptrex

Share this post


Link to post
Share on other sites
doudou

I don't think so RegFreeCOM Au3X Example :idea:

I know what you mean, however, COM isolation is only suitable for clients that are compiled with a manifest referencing specific components. You can't use it with pure scripting clients but only in an application that has exclusive privilege to use AU3Aut on the target system.

Of course, it is a perfect solution if you have a standalone app that needs to be distributed along with some AU3 scripts which it (and no one else) calls at runtime.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
Shafayat

This is Godly. I'm currently testing it.

I must say I'm am impressed!

Keep up the good work.


[Not using this account any more. Using "iShafayet" instead]

Share this post


Link to post
Share on other sites
ptrex
doudou

I must say I'm am impressed!

Keep up the good work.

Anyhow good job so far !

Thanks for your encouraging support, guys. I thought a new release would be a worthy answer :idea: So I made it (s. top post).


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
JRSmile

brilliant, if you now can add a feature like "__GetMeCoke" i would marry you.

Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites
doudou

brilliant, if you now can add a feature like "__GetMeCoke" i would marry you.

This feature is already built in but you have to transfer 2 USD to Coca Cola Corp. every time you use it.

Sorry, I cannot marry you: my other 3 wives and 4 husbands voted against. But your proposal certainly honors me.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
trancexx

You are using open with ShellExecuteExW. This means it doesn't work for me for scripts.

Nice one doudou.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
doudou

You are using open with ShellExecuteExW. This means it doesn't work for me for scripts.

What verb is registered on your system to run .au3?

ShellExecuteEx with "open" seemed to be most universal (as it works for compiled EXE too). Any suggestions?


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
trancexx

Run Lola run.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
doudou

Run Lola run.

Hmm... I suppose I could try NULL

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
doudou

Especially for trancexx :idea: and people who mess with their registries: version 1.0.2 (s. top post) of the DLL executes AU3s no matter what verb is associated with them.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
JRowe

Hmm, LuaCOM and this means AutoIt based Scite GUI mods - anyone want to take a whack at how that would work out? I'm not very fluent in Lua.

Edited by JRowe

Share this post


Link to post
Share on other sites
doudou

Hmm, LuaCOM and this means AutoIt based Scite GUI mods - anyone want to take a whack at how that would work out? I'm not very fluent in Lua.

The correct link is LuaCOM.

I'm not firm in LUA either nor I use SCite but since LuaCOM supports this:

luacom_obj = luacom.CreateObject(ProgID)

You should be able to use AU3Aut from there (as long as LuaCOM wouldn't try to do GetTypeInfo on it - I don't think so and it should be documented somewhere on their site anyway). But don't ask me about details on Lua libraries integration in Scite...

Edited by doudou

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites
JRowe

Thanks, I think this is one for the general forum. Excellent UDF, I foresee many valuable uses. Thanks!

Also, good catch. That prepended http bites me in the ass quite often.

Share this post


Link to post
Share on other sites
JRowe

I got the DLL registered by using the full path to AU3Aut.dll , but now the vbs test doesn't work. Any thoughts on this?

Edited by JRowe

Share this post


Link to post
Share on other sites
doudou

I got the DLL registered by using the full path to AU3Aut.dll , but now the vbs test doesn't work. Any thoughts on this?

What do you mean "doesn't work"? What script and what does WSH say?

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×