8

I'm doing some automation via a combination of windows message sending directly to HWNDs and calls to a COM server exposed by the automated application.

If there is more than one instance running, I need to be able to determine the process ID of the COM server so I can hit the same instance with the COM call as the one I'm sending windows messages to.

I can enumerate all the running COM servers with the running object table and get back monikers for all of them, but the COM objects themselves expose no methods I can use to get a window handle, thread ID, process ID, or anything of that sort.

Is there any way to figure out, based on a moniker or the actual binding COM object of the moniker, what the process ID of the COM server is?

Thanks!

1
  • No, making this info undiscoverable is very much by design. You need help from the server. Feb 18, 2011 at 21:09

2 Answers 2

6

If you control (write code for) both the server and the client you can add a method to your COM interface that would return the process / thread ID or anything of this nature (e.g. server hostname if it is remote) on the server end. I second @Hans - unless you have access to the server implementation you may be out of luck by design.

1
  • This isn't really really an attractive solution, since the server could then potentially lie about its PID. Nov 25, 2019 at 12:02
2

I believe the kimgr CoGetServerPID function will give you the process-id of your COM server. However, it only works if the process-id is <65k.

You can also use GetWindowThreadProcessId if you already have the window handle (HWND).

There's also a 3 Ways to Get a COM Server Process ID blog post that might be worth taking a look at. Haven't tried it myself though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.