Qwertronix Posted February 5, 2017 Share Posted February 5, 2017 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 More sharing options...
water Posted February 5, 2017 Share Posted February 5, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Qwertronix Posted February 8, 2017 Author Share Posted February 8, 2017 (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 February 8, 2017 by Qwertronix Link to comment Share on other sites More sharing options...
water Posted February 9, 2017 Share Posted February 9, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted February 9, 2017 Share Posted February 9, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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