GMK Posted February 21, 2013 Share Posted February 21, 2013 Let's say I have multiple PowerTerm Pro windows open. Global $oObj = ObjGet("", "PowerTermPro.Document") ; <-- Production command works ok for the first instance only Global $oObj = ObjGet("", "PowerTermPro.Document", 1) ; <-- Beta command gives COM Error: 0x80020006 Unknown name. Can anyone shed any light on this? How can I get access to multiple objects of the same class? Link to comment Share on other sites More sharing options...
jdelaney Posted February 21, 2013 Share Posted February 21, 2013 (edited) Use something like in the _ExcelBookAttach function? $o_Result = ObjGet("", "Excel.Application") If @error Or Not IsObj($o_Result) Then ;~ ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application object" & @CRLF) Return SetError(1, 1, 0) EndIf Local $o_workbooks = $o_Result.Application.Workbooks If Not IsObj($o_workbooks) Or $o_workbooks.Count = 0 Then ;~ ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application windows" & @CRLF) Return SetError(1, 2, 0) EndIf For $o_workbook In $o_workbooks Switch $s_mode Case "filename" If $o_workbook.Name = $s_string Then Return $o_workbook EndIf Case "filepath" If $o_workbook.FullName = $s_string Then Return $o_workbook EndIf Case "title" If ($o_workbook.Application.Caption) = $s_string Then Return $o_workbook EndIf Case Else ;~ ConsoleWrite("--> Error from function _ExcelAttach, Invalid Mode Specified" & @CRLF) Return SetError(1, 3, 0) EndSwitch Next Edited February 21, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
GMK Posted February 21, 2013 Author Share Posted February 21, 2013 (edited) To be able to send COM commands to the PowerTerm Pro object, the best way I've found so far is this: expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _PTProAttach ; Description ...: Attach to the first PowerTerm Pro object ; Syntax ........: _PTProAttach() ; Parameters ....: None ; Return values .: On Success - Returns an object variable pointing to a PowerTermPro.Document Application object ; On Failure - Returns 0 and sets @error: ; |@error - 0 ($_PTProStatus_Success) = No Error ; |@error - 1 ($_PTProStatus_GeneralError) = General Error ; Author ........: GMK ; =============================================================================================================================== Func _PTProAttach() Local $sFuncName = "_PTProAttach" Local $oDoc = ObjGet("", "PowerTermPro.Document") If Not IsObj($oDoc) Then __PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Object Creation Failed") Return SetError($_PTProStatus_GeneralError, 0, 0) EndIf $oDoc.ShowApplication Local $oReturn = $oDoc.GetApplication If Not IsObj($oReturn) Then __PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed") Return SetError($_PTProStatus_GeneralError, 0, 0) EndIf Return SetError($_PTProStatus_Success, 0, $oReturn) EndFunc ;==>_PTProCreate ; #FUNCTION# ===================================================================================================================== ; Name ..........: _PTProCreate ; Description ...: Creates a PowerTerm Pro object ; Syntax ........: _PTProCreate([$sSetupFile = ""[, $iCommType = ""[, $sTerminalName = ""[, $sHost = ""[, $sPort = ""]]]]]) ; Parameters ....: $sSetupFile - [Optional] PowerTerm Pro setup file location ; $iCommType - [Optional] Comm Type: ; $pt_Telnet = 0 ; $pt_Com = 1 ; $pt_Nsvt = 2 ; $pt_Lat = 3 ; $pt_Cterm = 4 ; $pt_Bapi = 5 ; $pt_Rlogin = 6 ; $pt_TAPI = 7 ; $pt_Superlat = 8 ; $pt_Nwlat = 9 ; $pt_Tn3270 = 10 ; $pt_Mssna = 11 ; $pt_Nwsaa_ipx = 12 ; $pt_Nwsaa_TCPIP = 13 ; $pt_Tn5250 = 14 ; $pt_Nsrouter = 15 ; $pt_Winappc = 16 ; $sTerminalName - [Optional] Terminal Name ; $sHost - [Optional] Host (IP or DNS Address) ; $sPort - [Optional] Port ; Return values .: On Success - Returns an object variable pointing to a PowerTermPro.Document Application object ; On Failure - Returns 0 and sets @error: ; |@error - 0 ($_PTProStatus_Success) = No Error ; |@error - 1 ($_PTProStatus_GeneralError) = General Error ; |@error - 3 ($_PTProStatus_InvalidDataType) = Invalid Data Type ; |@error - 4 ($_PTProStatus_InvalidValue) = Invalid Value ; |@error - 5 ($_PTProStatus_FileNotFound) = File Not Found ; |@extended - Contains invalid parameter number ; Author ........: GMK ; ================================================================================================================================ Func _PTProCreate($sSetupFile = "", $iCommType = "", $sTerminalName = "", $sHost = "", $sPort = "") Local $sFuncName = "_PTProCreate" Local $oDoc = ObjCreate("PowerTermPro.Document") If Not IsObj($oDoc) Then __PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Object Creation Failed") Return SetError($_PTProStatus_GeneralError, 0, 0) EndIf If $sSetupFile <> "" And Not FileExists($sSetupFile) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_FileNotFound") Return SetError($_PTProStatus_FileNotFound, 1, 0) EndIf If $iCommType <> "" And Not IsInt($iCommType) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType") Return SetError($_PTProStatus_InvalidDataType, 2, 0) EndIf If $iCommType <> "" And Not ($iCommType >= 0 And $iCommType <= 16) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue") Return SetError($_PTProStatus_InvalidValue, 2, 0) EndIf If $sTerminalName <> "" And Not IsString($sTerminalName) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType") Return SetError($_PTProStatus_InvalidDataType, 3, 0) EndIf If $sHost <> "" And Not IsString($sHost) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType") Return SetError($_PTProStatus_InvalidDataType, 4, 0) EndIf If $sHost <> "" And Ping($sHost) = 0 Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue") Return SetError($_PTProStatus_InvalidValue, 4, 0) EndIf If $sPort <> "" And Not IsString($sPort) Then __PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType") Return SetError($_PTProStatus_InvalidDataType, 5, 0) EndIf $oDoc.ShowApplication Local $oReturn = $oDoc.GetApplication If Not IsObj($oReturn) Then __PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed") Return SetError($_PTProStatus_GeneralError, 0, 0) EndIf Switch $iCommType Case 0 _PTProSessionSetTelnetParameters($oReturn, $sTerminalName, $sHost, $sPort) Case 1 To 16 _PTProSessionSetCommType($oReturn, $iCommType) _PTProSessionSetTerminalName($oReturn, $sTerminalName) _PTProSessionSetHostName($oReturn, $sHost) _PTProSessionSetCommPort($oReturn, $sPort) EndSwitch _PTProSessionOpen($oReturn) If $sSetupFile <> "" Then _PTProOpenSetupFile($oReturn, $sSetupFile) If $sHost <> "" And Not _PTProIsCommunicationOpen($oReturn) Then __PTProErrorNotify("Warning", $sFuncName, "", "Unable to connect to server.") Return SetError($_PTProStatus_Success, 0, $oReturn) EndFunc ;==>_PTProCreate So it's very backwards--create or attach to a "document," then get the application from there and you can send your commands. Edited January 3, 2014 by GMK 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