Jump to content

Communication between AutoIt and VBScript


Recommended Posts

@mLipok  

Quote

ptrex is the one who can answer on my question ?

This is the way trancexx created the feature in AutoIT.

You can use either way to use the IID GUID

In case there is only 1 interface in the COM Module you can refer to the IID Flag = DEFAULT

Some ActiveX modules have multiple IID's so you need to refer to the by the relevant IID GUID.

 

 

Link to comment
Share on other sites

13 minutes ago, ptrex said:

This is the way trancexx created the feature in AutoIT.

Could you point me to the post I want to focus on this discussion.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@mLipok 

Sorry I don't have a post to refer to, this info is from old discussions with trancexx many years ago.

I don't have access to the source code either.  But If you use some debugging tools like the very old but still usefull MS OLEView.

You can see the COM object details to see the IID GUID's.

 

Link to comment
Share on other sites

@Professor_Bernd  

This is the registration free AutoIT example that shows a TOOLTIP on your screen.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=Y

Global $hActiveX

; Load the ActiveX Module
If @AutoItX64 Then
    $hActiveX  = DllOpen(@ScriptDir & "\AutoItX3_x64.dll")
Else
    $hActiveX  = DllOpen(@ScriptDir &  "\AutoItX3.dll")
EndIf
;MsgBox(0,"x64",@AutoItX64)

; Object identifiers
Global Const $sCLSID = "{1A671297-FA74-4422-80FA-6C5D8CE4DE04}"
Global Const $sIID = Default ; Or use keyword Default if you want to use the Default interface ID

; 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

; Create the hActiveX
Local $oAutoIt = ObjCreate($sCLSID, $sIID, $hActiveX)

If $oAutoIt = 0 Then MsgBox(16,"Error", "Could not create the object, Common problem ActiveX not registered.")

; This will create a tooltip in the upper left of the screen
$oAutoIt.ToolTip ("This is a tooltip", 450, 200)
$oAutoIt.Sleep (3000)    ; Sleep to give tooltip time to display

$oAutoIt = ""
DllClose($hActiveX)

Enjoy !

Link to comment
Share on other sites

4 hours ago, ptrex said:

This is the registration free AutoIT example that shows a TOOLTIP on your screen.

@ptrex

I've read your "Hex Editor COM Control" thread and your posts up here carefully. Thanks for the code of the registration free AutoIT example! 👍

How can you use this in VBScript? So how to register AutoItX.dll in ROT and call AutoItX functions in VBScript?

 

I created the following code in a VBScript which should use the AutoItX registered with regsvr32.

Dim oAutoIt
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
oAutoIt.ToolTip "This is a tooltip"
oAutoIt.Sleep 3000  ' Sleep to give tooltip time to display
oAutoIt.ToolTip ""  ' Remove the tooltip

When I run the VBScript directly in Windows Explorer, an error comes up saying "Object cannot be created." In PSPad's VBScript exactly the same code worked. I suspect it will be the same when creating an AutoItX object registered in ROT. More likely that will work in PSPad's VBScript as well.

So if you need a test environment, I can create a PSPad test version for you.

 

Please excuse me for not being full force on this topic. COM, ROT, the "evil" AutoIt functions and the constant switching between VBScript and AutoIt are all that can fit in my head at the moment. :lmao: Next month I should be able to properly address how to register an ActiveX DLL (AutoItX.dll) in ROT and use it in VBScript. I hope I can ask you for help then. :)

Link to comment
Share on other sites

@Professor_Bernd  

You have 2 problems, one that can be fixed the other is not possible 

1. To get rid of the COM error.

You run x86 COM object on a x64 OS.  This will not work. You need to tell the vbscript host  to execute it as x86 like this  

run %windir%\SysWoW64\cmd.exe

and next your vbscript : wscript Test.vbs

2. The vbscript running AutoITX will run but not show anything. Because vbs does not have access to the Windows API's out of the box.

extend your script by adding this line msgbox "This was a tooltip"

And run again.

WORK AROUNDS :

1. Let vbscript run a AutoIT compiled script to show the ToolTip

2. Use DYNACALL to extend vbscript to access Windows API's

https://www.itprotoday.com/devops-and-software-development/rem-calling-win32-api-vbscript-code

Example calling a msgbox using WinAPI:

Quote

Option Explicit
Dim UserWrap 
Set UserWrap = CreateObject("DynamicWrapper")

' Call MessageBoxA(), first register the API function
UserWrap.Register "USER32.DLL", "MessageBoxA", "I=HsSu", _
                 "f=s", "R=l"
' now call the function
UserWrap.MessageBoxA Null, "MessageBox (ANSI)", _
        "From DynaWrap Object", 3

 

Link to comment
Share on other sites

14 hours ago, ptrex said:

2. Use DYNACALL to extend vbscript to access Windows API's

Thanks for your information, I may use that later.

14 hours ago, ptrex said:

You run x86 COM object on a x64 OS.

This is strange to me, since AutoItX also has an AutoItX3_x64.dll, but what you say works. (Maybe only the AutoItX3.dll is registered!?) But that is not important, it should only serve the demo, which can thus be created much easier.

14 hours ago, ptrex said:

2. The vbscript running AutoITX will run but not show anything. Because vbs does not have access to the Windows API's out of the box.

I don't understand that either, because in this case no access to the Windows API is needed. Only an access to the COM object of AutoItX. Here is an example without ToolTip:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
PID = oAutoIt.Run("Notepad.exe", "", oAutoIt.SW_SHOWNORMAL)
MsgBox "Notepad is closed"
oAutoIt.ProcessClose PID

Save the code as Test.vbs and (as you said) start the Test.vbs with "C:\Windows\SysWOW64\wscript.exe". (Or you can just drop the Test.vbs on the wscript.exe).

Can you show me how to register the AutoItX3.dll in the ROT and use it in this example (Test.vbs)? Or is that too much work?

Link to comment
Share on other sites

@Professor_Bernd  

I am not sure what your are trying to achieve the ROT ?  

Please read this first 

https://docs.microsoft.com/en-us/windows/win32/com/registering-objects-in-the-rot

The ROT updates are handled automatically when a COM server starts windows will add this to he ROT as a COM server.

So I am not sure where you are heading now with your last question ... 

Bottom line is that whatever your are trying to achieve with AutoItx3.dll it will NEVER give you access to all windows API's. 

Because this is by design.

 

So you will have to chose between the 2 workarounds that I mentioned in my prior post.

Link to comment
Share on other sites

1 hour ago, ptrex said:

I am not sure what your are trying to achieve the ROT ? 

Please excuse, some things have become quite convoluted. :'(

My intention is to use AutoItX in PSPad's VBScript without registering it in the system with regsvr32. PSPad4AutoIt3 should become fully portable, so independent of a registration in the system by the user.

My idea was to create an Au3 script, use your "HEX Editor COM Control" and LarsJ's "IRunningObjectTable Interface" to register the "AutoItX3.dll" in the ROT and use the AutoItX COM objects in PSPad's VBScript. In this post LarsJ gave a hint how creating an AutoItX COM object in an Au3 script could work.

Since this has become a bigger topic than I thought and does not belong in this thread, I have created a separate thread "Use AutoItX as COM ROT object, without regsvr32 registration". Please read more there. :)

Edited by Professor_Bernd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...