Jump to content

ObjGet (Beta) giving COM error


Recommended Posts

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 post
Share on other sites

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 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 post
Share on other sites

To be able to send COM commands to the PowerTerm Pro object, the best way I've found so far is this:

; #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 by GMK
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mbee
      Hi!
      I'm using Maps (and I love 'em!), so I have to use the latest AutoIt Beta. I've switched to Beta mode, and the graphical debugger doesn't even show up in the Explorer context menu (not surprising). So I'd like to use _Dbug (rather than a large number of MsgBox statements), but it fails when it encounters a Map function (such as MapExists). I've made a request for a version that will work with the Beta, but going on past history, I don't expect an answer anytime soon.
      I'm not necessarily asking for someone else to modify _Dbug, because I can probably do it myself, as long as I know how to adapt it to use the Beta. Can someone please enlighten me as to how to adapt a UDF or other function to use AutoIt Beta?
      Thanks!
    • By Rhidlor
      So I'm trying to do some as400 automation and hit a wall when trying to get a COM object. The code on line 8 is failing, the as400.ws file opens with PCSWS.exe so I tried using that as the file path too but that didn't work either. Any and all help is greatly appreciated! 
       
      $file = "C:\Users\Rhidlor\Desktop\as400.ws" If Not FileExists($file) Then MsgBox(0, "Error", "Error finding file") Exit EndIf $object = ObjGet($file) If @error Then MsgBox(0, "Error", "Error getting object") Exit EndIf $object.SendKeys("05")  
    • By nitron
      Hy All,
       
      again I got a question.
      I try to convert
      wmic PATH Win32_videocontroller GET adapterram
       
      i tried to to it like in this example but my knoledge is not good enough
         Local $oWMI = ObjGet("winmgmts:root\CIMV2")
         Local $oDisks = $oWMI.ExecQuery("select * from WIN32_DiskDrive")
       
      So i tired 
         Local $oWMI = ObjGet("winmgmts:root\CIMV2")
         Local $oGMRam= $oWMI.ExecQuery("Win32_videocontroller")
         $Memory=$oGMRam.adapterram
      but this does not work.
      I like to understand what i need to do?
       
    • By qsek
      Im not sure if this is intended but normally Autoit variables are always passed as copies (except objects i think).
      But below i observed an unconsistency when copying maps with nested maps inside.
      Issue:
      If you create a nested map1 and copy it to a new map2, changing a nested value in map2 will also change the nested value in map1
      Dim $player[] Dim $sub[] $player.test1 = 1 $player.test2 = $sub $player.test2.child1 = "org" $player.test2.childext = $sub $player.test2.childext.child1 = "org2" $playerold = $player ; make a copy of the whole map ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original nested value in $player $playerold.test2.child1 = "changed" ; edit a nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF) ; original nested value in $player changed ConsoleWrite("---------------------" & @CRLF) ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player $playerold.test2.childext.child1 = "changed2" ; edit a level2 nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original level1 nested value in $player stayed the same ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player changed  
    • By water
      Lets say I open 12 Excel workbooks and use _Excel_BookList to get a list of this open workbooks. It can take the function up to 45 seconds to return the result.
      Each call to ObjGet takes longer then the previous one while incrementing the index:
      I searched the forum but only found some threads from 2008 discussing the processing of the ROT (Running Objects Table).
      Does someone have an idea how to enhance this function (some miraculous WinAPI calls ...)?
      #include <Excel.au3> Local $oExcel = _Excel_Open() Global $iTimer = TimerInit() Global $aWorkbooks = _Excel_BookListEX() ConsoleWrite("Runtime for _Excel_BookList: " & TimerDiff($iTimer) & @CRLF) Func _Excel_BookListEX($oExcel = Default) ; Error handler, automatic cleanup at end of function Global $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc_RT") #forceref $oError Local $aBooks[1][3], $iIndex = 0 If IsObj($oExcel) Then If ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, 0, 0) Local $iTemp = $oExcel.Workbooks.Count ReDim $aBooks[$iTemp][3] For $iIndex = 0 To $iTemp - 1 $aBooks[$iIndex][0] = $oExcel.Workbooks($iIndex + 1) $aBooks[$iIndex][1] = $oExcel.Workbooks($iIndex + 1).Name $aBooks[$iIndex][2] = $oExcel.Workbooks($iIndex + 1).Path Next Else If $oExcel <> Default Then Return SetError(1, 0, 0) Local $oWorkbook, $sCLSID_Workbook = "{00020819-0000-0000-C000-000000000046}" While True $iTimerList = TimerInit() $oWorkbook = ObjGet("", $sCLSID_Workbook, $iIndex + 1) If @error Then ExitLoop ConsoleWrite("ObjGet for instance " & $iIndex + 1 & ": " & TimerDiff($iTimerList) & @CRLF) ReDim $aBooks[$iIndex + 1][3] $aBooks[$iIndex][0] = $oWorkbook $aBooks[$iIndex][1] = $oWorkbook.Name $aBooks[$iIndex][2] = $oWorkbook.Path $iIndex += 1 $oWorkbook = 0 WEnd EndIf Return $aBooks EndFunc ;==>_Excel_BookListEX  
×
×
  • Create New...