Jump to content

ObjCreate attaches only once per instance?


Recommended Posts

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!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...