comsession-0-isolation

Can processes in session 0 share an out of process COM server, please?


In Windows 7, I have an out of process COM server, say "MyComServer.exe". I register it as CLSCTX_LOCAL_SERVER and REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED.

In interactive sessions, session number > 0, only one instance of my MyComServer.exe runs, no matter how many clients are running. Say I'm running 5 excels, 3 matlabs and 7 others all using my COM server, I only see 1 MyComServer.exe running. This is fine, this is what I intended.

If several sessions are active, say sessions 1, 2 and 3 then I see 3 instances of MyComServer.exe. Using tasklist I can see each instance is running in a different session. This is fine as well, as I intended.

However, If I use it from session 0 I see an instance per client. Say I have 3 windows services all using it, then I see 3 instances of MyComServer.exe. Using tasklist I see all 3 of them run in session 0. Can processes in session 0 share an out of process COM server, please?

Investigation this issue I have noticed that PostMessage doesn't work between processes in session 0. Reading the documentation I understand PostMessage is not supposed to cross sessions, meaning a process in session 0 cannot post a message to a process in session 1. I have noticed that, while a process in session 1 can post a message to another process in the same session, a process in session 0 cannot post a message to any other process, even if the target is also running in session 0. Can someone please confirm this? It seems to be at odds with Microsoft documentation.

Thanks.


Solution

  • Starting with Vista, session 0 only hosts services and system processes. User applications run in session 1, 2, etc.

    PostMessage and SendMessage don't work in session 0. It's not possible to send message across session boundaries. As for sending messages within session 0 it doesn't make sense since there are only services and system processes in this session.

    Concerning COM, you should notice that session 0 isolation also applies to COM+ server applications and COM out-of-process applications running under anything else than the interactive user. See Session 0 isolation, COM and COM+:

    Session 0 isolation is not limited to NT services. It also applies to COM+ server applications and COM out-of-process applications running under anything else than the interactive user. So all problems related to services living in a different Terminal Server session from the first logged in user now also apply to dllhost processes (COM+ or surrogated COM dlls) and COM server applications.