Jump to content
Sign in to follow this  

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?

Share this post

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)
 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)
 For $o_workbook In $o_workbooks
  Switch $s_mode
   Case "filename"
    If $o_workbook.Name = $s_string Then
     Return $o_workbook
   Case "filepath"
    If $o_workbook.FullName = $s_string Then
     Return $o_workbook
   Case "title"
    If ($o_workbook.Application.Caption) = $s_string Then
     Return $o_workbook
   Case Else
;~  ConsoleWrite("--> Error from function _ExcelAttach, Invalid Mode Specified" & @CRLF)
    Return SetError(1, 3, 0)
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.

Share this post

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)
Local $oReturn = $oDoc.GetApplication
If Not IsObj($oReturn) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
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)
If $sSetupFile <> "" And Not FileExists($sSetupFile) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_FileNotFound")
Return SetError($_PTProStatus_FileNotFound, 1, 0)
If $iCommType <> "" And Not IsInt($iCommType) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 2, 0)
If $iCommType <> "" And Not ($iCommType >= 0 And $iCommType <= 16) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue")
Return SetError($_PTProStatus_InvalidValue, 2, 0)
If $sTerminalName <> "" And Not IsString($sTerminalName) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 3, 0)
If $sHost <> "" And Not IsString($sHost) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 4, 0)
If $sHost <> "" And Ping($sHost) = 0 Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue")
Return SetError($_PTProStatus_InvalidValue, 4, 0)
If $sPort <> "" And Not IsString($sPort) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 5, 0)
Local $oReturn = $oDoc.GetApplication
If Not IsObj($oReturn) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
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)
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

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
Sign in to follow this  

  • Similar Content

    • water
      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  
    • kara2004
      By kara2004
      Hi there,
      I have a problem using the latest two betas of au3stripper.exe.
      Compiling my script using V17.224.935.6 works fine, the next two releases (18.624.1847.0 and 18.624.1847.1) show an error:
      !==> *** ERROR: stopping process because include file not found :#include <INCLUDE_FILE.au3> !==> *** Checked these directories : !==> C:\Program Files (x86)\AutoIt3\include\INCLUDE_FILE.au3 !==> SCRIPT_DIR\INCLUDE_FILE.au3 !==> SCRIPT_DIR\INCLUDE_FILE.au3 !>18:42:00 --------------------------------------------------------------- !>18:42:00 Au3Stripper ended with errors, using original scriptfile.rc:999 !>18:42:00 --------------------------------------------------------------- Changing the include line according to the helpfile (using "..." for includes in script dir and <..> for includes in the au3-include-dir won't help!?
    • qsek
      By qsek
      Can somebody try to reproduce this bug?
      It would be helpful to know if this issue appeares on other environments too.
      Sometimes values of certain keys will return empty even if expicitly assigned a value before.
      Map is bigger than ~50 key/values pairs value is being worked with in a Function where a loop is iterating through the Map before retrieving the value there is a isMap/MapKeys/MapAppend/MapRemove check on the Map value. Dim $mMap[] ; Generate random key strings For $i = 0 To 100 $RndKey = "" For $i2 = 0 To 4 $RndKey &= Chr(Random(65,90,1)) Next $mMap[$RndKey] = 999 next ConsoleWrite("-----------1-------------" & @CRLF); Unpredictable blank values MapDisplay1($mMap) ConsoleWrite("-----------2-------------" & @CRLF); ByRef always works MapDisplay2($mMap) ConsoleWrite("-----------3-------------" & @CRLF); not in a function always works For $i In MapKeys($mMap) isMap($mMap[$i]) ConsoleWrite($i&": "&$mMap[$i]&@CRLF) Next Func MapDisplay1( $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ;same problem with isMap($m_Map[$i]), MapKeys($m_Map[$i]), MapAppend/MapRemove but NOT with MapExists($m_Map,$i) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc Func MapDisplay2( ByRef $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc  
      The value is not lost or overwritten on the global map, only on the local map inside the function.
    • WoodGrain
      By WoodGrain
      Hi All,
      I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below.
      I'm using these sources:
      $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP:
      ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
    • TheDcoder
      By TheDcoder
      Hello Again! I previously stumbled upon a topic asking for maps datatype's instructions... I too wasn't sure what a map is until I tried it... So I am making this topic to help other newbies (and some oldbies) better understand the Maps datatype of AutoIt! Lets start!
      A Note for Readers
      The maps datatype is still in development and is currently in Alpha Stage (More Risky than Beta) and its unstable, so AutoIt can crash indefinably while using Maps! I can't guarantee if this will be implemented in stable versions, this is a fairly new thing to AutoIt coders & in my honest opinion I don't see any use for it Maps are the best datatype in AutoIt, Very Useful ... Not hurting anyone though .  Also the maps datatype is DISABLED IN STABLE VERSIONS, So you need to install the latest beta version of AutoIt to make maps work . If you find any bugs while using a map, please report it in the Official Bug Tracker
      Introduction To Maps
      Maps are just like arrays, instead they use "keys" to access elements inside them... A key can be either a string or an integer (Other datatypes work too but they are converted to a integer [Equivalent to Int($vKey)] before assignment [Source]). Although Integers don't represent the order of elements in a map unlike in an array...
      Declaring Maps
      Its similar to declaring an Array:
      ; This is the only way to declare a map ; You must have a declarative keyword like Dim/Global/Local before the declaration unless the map is assigned a value from a functions return Local $mMap[] ; Don't insert any numbers or strings it! Simple, Isn't it?
      Using Maps
      Using maps is similar to arrays (again!):
      Local $mMap[] ; Lets declare our map first! ; Adding data to maps is easy... ; This is our key ; | ; v $mMap["Key"] = "Value" ; <--- And our value! ; A key is Case-Sensitive meaning "Key" is not same as "key"! $mMap["key"] = "value" ; Not the same as $mMap["Key"]! ; There are 2 different ways to access an element in a map $mMap["Key"] ; 1st Method $mMap.Key ; 2nd Method  Enumerating Maps
      Its quite easy to enumerate through arrays but what about maps? how can I enumerate through them!?
      #include <MsgBoxConstants.au3> ; Lets create our map first Local $mMap[] ; Lets add some information to the map, feel free to modify & add new elements $mMap["Name"] = "Damon Harris" $mMap["Alias"] = "TheDcoder" $mMap["Gender"] = "Male" $mMap["Age"] = 14 $mMap["Location"] = "India" $aMapKeys = MapKeys($mMap) ; MapKeys function returns all the keys in the format of an array Local $sProfile = "Profile of " & $mMap["Name"] & ':' & @CRLF ; We will use this string later For $vKey In $aMapKeys ; We use this to get the keys in a map :) $sProfile &= @CRLF & $vKey & ': ' & $mMap[$vKey] ; Add some details to the profile string using our map! Next MsgBox($MB_ICONINFORMATION + $MB_OK, "Profile", $sProfile) ; Finally display the profile :) It is easy as always
      Multi-Dimensional Maps
      Now now... I know that you are a little confused that how can an multi-dimensional maps exist... Although I am not 100% sure if its called that but lets continue:

      #include <MsgBoxConstants.au3> ; Multi-Dimensional maps are just maps in a map Local $mMapOfMapsvilla[] ; This map will store an other map Local $mParkMap[] ; This Park map will be inserted in the Mapsvilla's map :P $mMapOfMapsvilla["Map Item 1"] = "Town Hall" $mMapOfMapsvilla["Map Item 2"] = "Police Station" $mMapOfMapsvilla["Map Item 3"] = "Shopping Mall" $mMapOfMapsvilla["Map Item 4"] = "Residential Area" $mMapOfMapsvilla["Map Item 5"] = "Park" $mParkMap["Map Item 1"] = "Cottan Candy Stand" $mParkMap["Map Item 2"] = "Public Toilet" $mParkMap["Map Item 3"] = "Woods" $mMapOfMapsvilla.Park = $mParkMap MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla["Map Item 1"]) ; Will display Town Hall MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla.Park["Map Item 1"]) ; Will display Cottan Candy Stand I am sure its easy for you to understand now
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. Help! My code does not respond to anything (or) I get an "Variable subscript badly formatted" error on the line of declaration...
      A. DONT USE F5 or Go, Instead use Alt + F5 or Tools -> Beta Run in SciTE (Make sure that you have Beta installed)
      Q #2. Why are you using "m" in-front of every map variable?
      A. Best coding Practices: Names of Variables 
      Q #3. What are "Elements" which you mention frequently???
      A. This is a newbie question (I have no intention of insulting you ), so I guess you are new to programming. "Elements" are data slots inside a Map (or an Array), you can imagine elements as individual variable which are stored in a Map. You can access them using "keys", Please refer to "Introduction to Maps" section at the starting of this post
      Q #4. Are Maps faster than Arrays?
      A. You need to understand that Maps have different purpose than Arrays. Maps are designed to store data dynamically (like storing information for certain controlIDs of GUI) and Arrays are designed to store data in a order (for instance, Storing every character of a string in an element for easy access). If you still want to know then if Maps are faster, then the answer is maybe... Maps are *supposed* (I am not sure ) to be faster in addition of elements (while Arrays are painfully slow while adding or removing elements). Here (Post #24) is a benchmark (Thanks kealper! )
      More FAQs coming soon! Feel free to ask a question in the mean while