tags:

views:

76

answers:

1

Is there any way to determine the PID of a process that was started by instantiating a COM coclass?

For example:

MyApp.ApplicationClass anApp = new MyApp.ApplicationClass();

would start the process myapp. Potentially there are already a lot of myapp processes running when this code is executed.

My current solution to acquire the latest PID feels a bit awkward: I memorize the list of running processes before creating the new instance and take the delta of running myapp PIDs when the new instance was created.

Is there an standard/better way to accomplish this?

Edit: The PID is later used to identify/monitor the created process.

+2  A: 

It looks like you also control the code for MyApp ?

If so, I'd recommend the best way to do this is to add a method to MyApp called GetPid(), and just call anApp.GetPid()...

Orion Edwards
+1 Thanks, good hint! It wouldn't be impossible to convince the code owners to provide an additional method or interface, however, if possible I would prefer a non-intrusive solution.
olli
Despite other input, I honor your creative suggestion and accept your answer. In the end I used this intrusive solution. However, I would still have preferred a non-intrusive solution... But perhaps there is none :-)
olli