终止 SYSTEM 帐户下的 ATL COM 进程?

发布于 2024-12-03 01:28:42 字数 334 浏览 4 评论 0原文

我有一个在本地系统帐户下运行的 .NET Windows 服务。然后,该服务使用 COM Interop 在 Visual Studio 6 上运行以 ATL 编写的 COM 组件。然后,该 COM 组件在 SYSTEM 帐户下运行。我知道我可以冒充另一个帐户,但现在我想把东西留在原处。

问题是Windows服务停止后,COM组件仍然运行。我也无法杀死该进程。任务管理器不会杀死它,所以我从命令行尝试了 TaskKill。这甚至说它成功终止了进程,但当我检查任务管理器时它仍在运行。我已经尝试过 PSKill,但显示访问被拒绝。

我已经用尽谷歌寻找解决方案。有人可以帮忙吗?

另外,为什么它仍然保持运行?

I have a .NET Winddows service which runs under the Local System account. This service then runs a COM component that was written in ATL on Visual Studio 6 using COM Interop. This COM component then runs under the SYSTEM account. I know I can impersonate another account but for now I want to leave things where they are.

The problem is that after the windows service stops, the COM component remains running. I can't kill the process either. Task Manager won't kill it so I tried TaskKill from the command line. This even says it terminated the process successfully but when I check task manager it is still running. I have tried PSKill but that says access denied.

I've exhausted Google looking for a solution to this. Can anyone help?

Also, why does it remain running anyway?

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

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

发布评论

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

评论(1

鸢与 2024-12-10 01:28:42

杀死一个进程只是一个权限问题。假设 Vista/7 启用了 UAC,如果您不以管理员身份运行,您将无法终止系统进程。注意 - 仅成为本地管理员组的成员是不够的。您必须使用“以管理员身份运行”启动任务管理器/进程资源管理器/ pskill 或其他任何内容,才能以管理权限实际运行它们。否则,您只是普通用户,就会被拒绝。

至于 COM 服务器仍然存在:COM 服务器有一个引用计数,只有在计数降至 0 后它们才会自行关闭。在您的情况下,服务器可能由于以下几个原因而不会关闭:

  1. 您的客户端未正确释放COM 服务器创建的所有实例。我不是 .NET 程序员,所以我不能说这是否是您应该关心的事情,或者垃圾收集是否会为您做这件事。如果您的服务由于崩溃或外部终止而在没有正确清理的情况下终止,那么您肯定会遇到这个问题。
  2. 无论创建者想到什么原因,服务器都可能在内部增加其引用计数。这甚至可能是服务器中的错误。
  3. IIRC,即使没有活动客户端,COM 也可能会让服务器运行一段时间。如果是这种情况,服务器将在几分钟后关闭。

Killing a process is just a matter of permissions. Assuming Vista/7 with UAC on, you won't be able to kill a system process if you're not running as an administrator. Note - it's not enough to be a member of the local administrators group. You must launch task manager / process explorer / pskill or whatever using "Run As Administrator" to actually run them with administrative permissions. Otherwise, you're just a regular user, and you're denied.

As for the COM server sticking around: COM servers have a reference count, and they shut themselves down only after the count drops to 0. In your case, the server might not shut down due to a few reasons:

  1. Your client is not properly releasing all instances created by the COM server. I'm not a .NET programmer, so I can't say whether this is something you should take care of, or whether the garbage collection does it for you. You will have that problem for sure if your service is terminated without cleaning up properly, as a result of a crash or external termination.
  2. The server might increase its reference count internally, for whatever reasons the creator had in mind. This might even be a bug in the server.
  3. IIRC, COM might leave a server running for a while even if there are no active clients. If that's the case, the server will shut down after a few minutes.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文