COMInterop attach to multiple instances of same ClassID

EuroEager2008 21 Reputation points
2021-01-29T11:02:01.087+00:00

I have read a lot of articles of how to "connect" (COMInterop) to all instances of an object in running processes.
However all these articles describe methods using RunningObjectTable and IMoniker to get the "System.__ComObject" for each running object, but the objects are actually the same.

This simple console solution clearly shows that they are indeed the same: https://1drv.ms/u/s!AoFGuPCXh0GgidYQmv_Zmzvm1uY12A?e=bwfbwb

I am using Office 2016, 32 bits and .Net 5

The linked solution is specifically trying to get objects from 2 different instances of excel process created by the program (csv files used for anonymization).
The result would be the same if the processes were created manually (alt-Excel) instead of programmatically.
Be sure that no other Excel processes are running when this program runs.

There "must" be a way of getting com objects for each of these process.
Is it? How?

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,179 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,611 Reputation points Microsoft Vendor
    2021-02-02T06:58:42.553+00:00

    @EuroEager2008 , based on my test, I have understood your question.

    First, I want to mention that GetRunningObjectTable Method means that Returns access to the Running Object Table (ROT) relevant to this binding process.
    Therefore, One process will return one System.__ComObject.

    Second, I noted that there is only one process even if I open two instances of excel. You can check it in the Task Manager->Details->Excel.exe.

    Finally, One excel process will only return one Comobject.

    Hope my explanation can help you.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.