Question about COM Objects

Tagged: 

This topic contains 8 replies, has 2 voices, and was last updated by Profile photo of Lery Lery 4 years, 1 month ago.

  • Author
    Posts
  • #4266
    Profile photo of Lery
    Lery
    Participant

    I'm working with a third party .NET COM object.  I realize that none of you have the documentation for this COM object.  I'm hoping with my description you can point me in the right direction to find what I need.

    First things first.  In PowerShell I create a new object

    New-Object -ComObject vendor

    If I were to execute that, I would get a bunch of stuff returned.  For example:

    ServerRevision               : 8400

    In turn, I could now run the following PowerShell:

    (New-Object -ComObject vendor).serverrevision

    One of the items that I see returned is a field called:  installedagents.

    This installedagents does not have an actual value.  It just says:  System.__ComObject

    My questions is.  What the heck do I do with that System.__ComObject?

    If it helps, when I pipe the COM object to get-member, the entry for installedagents says this:

    InstalledAgents              Property              IAeXInstalledAgents InstalledAgents () {get}

  • #4272
    Profile photo of Jonathan Tyler
    Jonathan Tyler
    Participant

    Hi Lery,

    Since I don't have your COM object, I used the most recent and closest one I could find; the Voice COM object in Windows 7.

    $voice = new-object -ComObject sapi.spvoice

    When I call the $voice variable, it shows me some properties, that as you show, have System.__ComObject.  When I call into one of those properties, it just enumerates its value.

    $voice.status

    PS C:\Windows\system32> $voice.status
    CurrentStreamNumber : 1
    LastStreamNumberQueued : 1
    LastHResult : 0
    RunningState : 1
    InputWordPosition : 57
    InputWordLength : 1
    InputSentencePosition : 8
    InputSentenceLength : 51
    LastBookmark :
    LastBookmarkId : 0
    PhonemeId : 7
    VisemeId : 0

    and finally, if I continue to dig into the property, I can get a specific value.

    $voice.status.CurrentStreamNumber

    returns 1.

    So you should be able to call into the properties just like you do native objects.  Hope this helps.  Someone may have much more experience with this than I do, but this is what I have done so far.

  • #4273
    Profile photo of Lery
    Lery
    Participant

    Thanks Jonathan.  I thought the same.  So I ran it before posting.  Here is the error returned:

     

    An error occurred while enumerating through a collection: The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).
    At line:2 char:1
    + (New-Object -ComObject Vendor).InstalledAgents
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.__ComObject:__ComObject) [], RuntimeException
    + FullyQualifiedErrorId : BadEnumeration

     

    You can see I'm running:

    (New-Object -ComObject Vendor).InstalledAgents

     

     

  • #4295
    Profile photo of Jonathan Tyler
    Jonathan Tyler
    Participant

    Dumb question, but have you attempted to generate an object first and then try to access the property?

    $vendor = new-object -comobject Vendor
    $vendor.InstalledAgents

    The only other thing I can think of is that you might have to use a .GetEnumerator() to start enumerating the items in the collection.  Beyond that, maybe someone else here has some input they can share.  I don't deal much with COM objects, so I am afraid we are quickly running to the limits of my knowledge...especially without further knowledge of the API behind your object.

  • #4340
    Profile photo of Lery
    Lery
    Participant

    Yes sir, tried that.  Error I get is:

    An error occurred while enumerating through a collection: The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).
    At line:9 char:1
    + $vendor.InstalledAgents
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.__ComObject:__ComObject) [], RuntimeException
    + FullyQualifiedErrorId : BadEnumeration

  • #4341
    Profile photo of Jonathan Tyler
    Jonathan Tyler
    Participant

    Let's try something a little different, then...

    Assign the .InstalledAgents property to a variable

    $agents = $vendor.InstalledAgents
    foreach ($agent in $agents)
    {
    $agent
    }

    This keeps powershell from doing an automatic enumeration, which may be causing the problem.  This way, you are getting a static copy of the InstalledAgents property and then enumerating over that collection.  Shot in the dark, but it might work.  Let me know.

  • #4346
    Profile photo of Lery
    Lery
    Participant

    Was worth the shot, but same error:

    The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
    At line:4 char:10
    + foreach ($agent in $agents)
    + ~~~~~~
    + CategoryInfo : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    I think it has something to do with the property.  For example, I can look at another property with no issues.  Example is ServerRevision.  When I ask for that property it returns:  8400

    But when I'm looking at all the properties available, InstalledAgents has System.__ComObject listed instead of actual values.  It should have maybe 5 string values in that property.  Not System.__ComObject.  I'm not sure why or what System.__ComObject means in a property.

  • #4349
    Profile photo of Jonathan Tyler
    Jonathan Tyler
    Participant

    Well, that is new information to work with, so I count that as some progress.

    My thoughts now (and again, not being familiar with your COM object, so this is a serious WAG, here) is that there may be an assembly that needs to be loaded so that it knows how to interpret that object from InstalledAgents.  Unfortunately, there is no magic ball I can look into to tell you what that might be.

    Perhaps the vendor has some documentation or you might find someone on the Internet who works for them who might be able to give you a clue.  The vendor might even have  a support forum where you can post a question.  That would probably be a long-shot, even if they did have a forum to post a question to.

    I'll keep thinking about it to see if something comes to mind, but I got nothin' right this minute.  Sorry I couldn't help more.

  • #4369
    Profile photo of Lery
    Lery
    Participant

    When I run:

    $a = New-Object -ComObject vendor
    $a

    In addition to figuring out why it does not work when I run $a.installedagents, I would like to understand what it means when I see System.__ComObject listed instead of an actual value?

You must be logged in to reply to this topic.