Question

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?

Was it helpful?

Solution

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top