I'm using JNA 4.5+
Is there a way to get the PID for an application started with: new COMLateBindingObject("X.Application", _boolean_)
?
Something like:
COMLateBindingObject obj = new COMLateBindingObject("myapp.Application", false);
SomeUtil.INSTANCE.getPidFor(obj);
I cannot use WMIC or a window handle based method because I have multiple concurrent running instances of same app.
Thanks in advance.
Finding this information about a COM server directly is unfortunately not possible. As Hans Passant puts it:
Not exposing these implementation details, and making it impossible to find out, is by design. Like the clipboard.
From COM Clients and Servers:
COM client applications do not need to be aware of how server objects are packaged, whether they are packaged as in-process objects (in DLLs) or as local or remote objects (in EXEs).
COM was simply designed so that you should not need to know these details. As suggested in the comments by the author of this question, you could resort to retrieving the process list with something like EnumProcesses
before and after launching the COM server and checking which processes were created, but even that would be a inaccurate hack at best.
I think you may have ran into an XY problem. If I were you, I would take two steps back and think about why I need to access the internals of COM (information about the process of a created COM server) and see if the problem I'm actually solving has a different solution. Perhaps you could elaborate on what you actually need the process ID for?