获取.NET中使用CreateObject启动的进程的进程ID

发布于 2024-08-24 20:40:15 字数 251 浏览 7 评论 0原文

我正在使用 VB.NET 作为一个 Web 应用程序,该应用程序使用 CreateObject 启动一些进程,如下所示:

Dim AVObject = CreateObject("avwin.application")

完成所有操作后,所有内容都会使用适当的发布函数关闭并停止,但是,由于某种原因该进程仍然存在。

有什么方法可以获取已启动进程的进程 ID,以便在终止之前显式终止它?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌吟 2024-08-31 20:40:15

我从来没有遇到过这个问题的具体解决方案,但从逻辑上讲,我将使用下面的伪逻辑创建一个解决方法(我认为它应该在受控环境中工作)

  • 将 CreateObject 包装在 CustomCreateObject(...) 中,
  • 在下面的方法中实现相同的顺序
  • 调用 System.Diagnostics.Process.GetProcessesByName(nameOfYourProcess),存储所有进程 id
  • 调用 CreateObject (...)
  • 再次调用 GetProcessesByName,现在获取新的进程 id 列表
  • 进程 id 位于后面的列表中,而不是在第一个,将是你所追求的。返回该值,以便调用者知道要监视的进程 ID。

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.
丢了幸福的猪 2024-08-31 20:40:15

完成所有操作后,所有内容都会关闭并停止使用适当的释放功能,但是,由于某种原因,该过程仍然存在。

您是否尝试强制执行 GC 或调用 ReleaseCOMObject () 方法?

最佳

阿德里亚诺

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文