user254875486
user254875486

Reputation: 11240

Get process id of process started with CreateObject in .NET

I'm using VB.NET for a web-application that starts some process using CreateObject, like this:

Dim AVObject = CreateObject("avwin.application")

After all is done everything get closed down en stopped using the proper release functions, however, for some reason the process remains.

Is there some way in which I can get the process id of the started process, in order to explicitly kill it just before termination?

Thanks

Upvotes: 4

Views: 3764

Answers (2)

Fadrian Sudaman
Fadrian Sudaman

Reputation: 6465

I never come across a specific solution to this problem, but logically I will create a workaround using below pseudo logic (I think it should work in a controlled environment)

  • Wrap the CreateObject in say CustomCreateObject(...)
  • In the method implements below in the same sequence
  • Call System.Diagnostics.Process.GetProcessesByName(nameOfYourProcess), stores all the process ids
  • Call CreateObject (...)
  • Call GetProcessesByName again and now get the new list of process ids
  • Process id that is in the later list and not in the first one, will be the one you are after. Return that so that the caller know the process id to monitor.

Upvotes: 2

Vagaus
Vagaus

Reputation: 4215

After all is done everything get closed down en stopped using the proper release functions, however, for some reason the process remains.

Have you tried to force a GC or called ReleaseCOMObject() method?

Best

Adriano

Upvotes: 1

Related Questions