Qwertronix

ObjCreate attaches only once per instance?

5 posts in this topic

Hello! I've got a strange behavior when trying to use AutoIt to automate an external piece of software (SmarTerm)

When first run when SmarTerm is already open, the following code works without issue and as expected the text "Test" appears in the SmarTerm active session:

Local $oSTA = ObjCreate("SmarTerm.Application")
Local $oSTS = $oSTA.ActiveSession()

$oSTS.Send("Test")

However, after running it ONCE, running it subsequently results in extra instances of SmarTerm being generated each time the same above script is run. I also haven't found any way to retrieve the object using ObjGet(). This continues until I close all SmarTerm windows/instances manually and then open a new window manually, after which running the above script again works fine only once. 

I'm mightily curious about why it's exhibiting this behavior with ObjCreate where the first run attaches the object to the existing window/instance and subsequent runs create new ones instead (even after the script *should* have purged the object when it closed...?), but my main goal is simply to have control of the application, so other any other workaround solutions someone can suggest would also help. 

Thanks!

Share this post


Link to post
Share on other sites



I usually do it this way (please check the Excel and Word UDF):

Local $oExcel = ObjGet("", "Excel.Application") ; Get an existing Excel Object
If @error Then 
    $oExcel = ObjCreate("Excel.Application") ; Create a new Excel Object
    If @error Then Exit MsgBox(0, "Error", "Error creating the Excel application")
EndIf

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks water! 

I ended up finding that and trying it as well, but it seems I'm hitting a wall unrelated to AutoIt and it's the application I'm trying to control that for some reason seems to keep the previous instance of a COM object alive without assigning it to the ROT (ObjGet("", "SmarTerm.Application") always gives the "name not found" COM error code) and forces AutoIt (or anything else, since I've now tried through AHK and VBS as well) into a new instance of the app on a Create call. 

I've got more to learn about COM/OLE before I can get around this issue it seems :\ 

Edited by Qwertronix

Share this post


Link to post
Share on other sites

Does the SmarTerm object modell provide a method to close the application?
Means: Your script starts a new instance and then ends leaving the application running.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Just googled and found the reference. http://www.esker.com/fm/others/eval-smarterm/bin1211/macro.pdf
Seems you need to call the Session.Close and Application.Quit methods:

Local $oSTA = ObjCreate("SmarTerm.Application")
Local $oSTS = $oSTA.ActiveSession()
$oSTS.Send("Test")
$oSTS.Close() ; Close the session
$oSTA.Quit() ; Close the application

Is there still a process hanging around after running this script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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