Article ID: 169321 - Last Review: July 11, 2005 - Revision: 2.5 INFO: COM Servers Activation and NT Windows Stations
This article was previously published under Q169321 On This PageSUMMARY
When a client requests a class object for a registered class, COM either
returns an existing class object or launches a process that is registered
as containing the requested class object. The process of obtaining a class
object reference for a requesting client (whether or not that results in
process creation or "launching") is called "activation."
Under certain conditions, COM may launch a new server process even when an existing class object is running and has been registered as multiple use. Moreover, when COM creates a new process that process may be launched in a new security environment known as a "window station" rather than sharing an existing window station such as the interactive window station. (For more information on window stations, search the Win32 SDK documentation for that phrase.) Understanding COM's algorithms for creating new processes and window stations during an activation request is important for several reasons. First, COM may create more than one process instance of a multiple-use class object because of security issues. Second, "single-use" servers will always be launched in separate processes, but they may or may not be launched in separate window stations. This difference might manifest itself to application code in certain unusual cases, such as when two COM servers try to communicate via window messages or secure communication facilities such as COM or RPC. Third, since the number of window stations that can simultaneously be created in Windows NT is limited, it is important to know when your COM server gets a new window station. This article examines different activation scenarios and explains when new processes and window stations are created. MORE INFORMATION
When COM creates a new server process or assigns a new window station to a
new server process depends on several factors:
Multiple-use ClassesA multiple-use class is a class that is registered with COM (via CoRegisterClassObject() API) specifying the REGCLS_MULTIPLEUSE flag. For such a class, COM normally uses the same instance of the server process for all client activation requests. However, for classes configured to run under the security of the launching users and in a few other cases, COM launches a new instance of the server process to service activation requests. When a new instance of the server process is thus launched, it is possible that the server process gets a new window station as well. We will examine the various scenarios below, but first we will discuss briefly why COM launches new processes containing requested class objects when an instance of the class object is already registered as a "multiple-use" class.First, when a COM class (more accurately, when an AppID associated with a COM class) is registered with the system to be run as "the launching user," the system administrator has set a certain security policy with respect to that class. The policy is that an activator should receive a class object inside a process that is running in the same security context as the activating code. This security policy can come into conflict with the server-defined behavior of having only one class factory object for all activation requests (as indicated by REGCLS_MULTIPLEUSE). COM prioritizes the security policy over application behavior. As a result, multiple-use servers registered to run as "the launching user" will not behave according to the normal rules of multiple-use. A new process will be launched for each activating security principal. Second, if a process not launched by COM running in a security context different from the one specified for the given CLSID registers that CLSID, that registration will fail(CoRegisterClassObject will return an error code CO_E_WRONG_SERVER_IDENTITY in this case). And, if an activation request later arrives a new process will be launched by COM with the security context specified for the CLSID/AppID. COM can't trust code calling CoRegisterClassObject() (an unsecured operation), it can only trust the registry setting (the registry is a secure database) to determine which class object to use and how to run it. This behavior prevents illicit machine-wide spoofing of class objects by unauthorized users. With that in mind, we now return to the issue of when new processes and window stations are created when multiple-use servers are launched by COM. Notice that the LUID of the client does not matter in any way in the multiple-use class case.
Single-Use ClassesNOTE: Single-Use classes should be avoided as much as possible. Single-use registration is a legacy setting and is intended to support older COM applications and to ease the porting of legacy non-COM applications to COM. It is strongly recommended that new classes be designed to support multiple- use class object registration. This is especially true in the case of servers with "This User" identity, where single-use classes cause the exact opposite effect of multi-use classes. They create a new server process and new window station per activation and, as we discuss below, this can cause resource problems under Windows NT.A single-use class is one that is registered with COM (via the CoRegisterClassObject() API) specifying the REGCLS_SINGLEUSE flag. For such a class, COM will always start a new instance of the class's server process for each activation request from any client (local or remote). For purposes of this article, the remaining question is: when will the server get a new window station as well?
Table Summarizing Scenarios---------------------------------------------------------------------------
| Multiple-Use Server
| (class factory has requested reuse)
| Activation Modes
|-------------------------------------------------------------------
| Interactive | As "This |As "Launching | Win32
Client | User | User" | user" | service
Local | Process launched | Process | Process | Service
| in the | launched in a | launched client | started on
| interactive window| new window | window station | first
| station on first | station on | on first | activation
| activation | first | request, | request
| request, | activation | subsequent | (new winsta
| subsequent | request, | requests from | or system/
| requests get | subsequent | the same SID/ | interactive
| existing class | requests get | window station | winsta
| object, | existing class | get existing | depending
| activations fail | object | class object, no| on service
| if no user logged | | sharing of class| config),
| on locally | | objects across | subsequent
| | | window stations | requests
| | | even if same SID| get
-------| | |-----------------| existing
Remote | | | Process launched| class
| | | in new winsta on| objects
| | | first activation|
| | | request by a |
| | | SID, subsequent |
| | | remote requests |
| | | by the same SID |
| | | get existing |
| | | class object; |
| | | class launched |
| | | by local user |
| | | reused by remote|
| | | callers with |
| | | same SID |
---------------------------------------------------------------------------
| Single-Use Server
| (new process created for each activation request)
| Activation Modes
|-------------------------------------------------------------------
| Interactive | As "This |As "Launching | Win32
Client | User | User" | user" | service
Local | Process always | Process always | Process always | N/A(only
| launched in the | launched in a | launched in | one
| interactive | new window | the window | activation
| window station, | station | station of | possible)
| if no interactive | | client process |
| window station | | |
| activation fails | | |
-------| | |-----------------|
Remote | | | if both SID and |
| | | LUID of the |
| | | client match |
| | | previous client |
| | | activation, |
| | | process launched|
| | | in existing |
| | | window station, |
| | | otherwise in new|
| | | windowstation |
Window Stations and Windows NT ResourcesIn this section we will examine the implications of creating new window stations under Windows NT and how that should affect the configuration of your COM server. As you will see, there is a limit to the number of window stations that can be created on a Windows NT machine. When that limit is exceeded, Windows NT will fail an attempt by COM to launch a new instance of the server process. Typically, an error message like the following appears:
Initialization of the dynamic link library d:\winnt\system32\kernel32.dll failed. The process is terminating abnormally. WARNING: Using Registry Editor incorrectly can cause serious, system-wide problems that may require you to reinstall Windows NT to correct them. Microsoft cannot guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk. The named value you need to edit appears under the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems NOTE: A window station can contain multiple desktops within it. In the discussion of "Launching User" servers above, wherever the window station of the local client process is mentioned, it should be considered as a shorter form for "window station and desktop". "Launching User" setting is really meant for legacy non-DCOM aware servers and should be used rarely. Such legacy servers expect to run in their own desktops. Thus, for MULTIPLEUSE "Launching User" servers, each client process in a different desktop within the same window station causes a new server process to be started in that window station/desktop. For SINGLEUSE "Launching User" servers, again, the server inherits the windows station/desktop of the client process. In Windows NT 4.0 Service Pack 4.0, COM attempts to re-use window stations. Prior to this, if a server is set to RunAs a specific user and if multiple instances of the server process are launched, each process will get its own window station. This leads to the window station limitations describe above. In SP4, COM will attempt to create all RunAs (that is, not "Activate as Activator" or "Launching User") servers that are set to run under the same user identity (or token) in the same window station. This eliminates the need for adjusting the desktop heap size in those cases where multiple server processes run with the same token. If, in your configuration, all servers are set to RunAs the same user, or multiple instances of the same RunAs server process run, then you should not reduce the desk top heapsize as suggested in the article. It is recommended that you leave it at the default value (3M) in this case. This is because, if you reduce the desktop heap, then the system can create more window stations/desktops; however, the number of processes that can run in a window station/desktop become progressively smaller. On the other hand, in your configuration, if you have multiple servers running with different tokens, then you will face the window station limitations. In this case, you should follow the suggestions in the article for reducing the desktop heap size. REFERENCES
For additional information about the desktop heap issue, please see the
following article in the Microsoft Knowledge Base:
142676
(http://support.microsoft.com/kb/142676/EN-US/
)
How to correct common User32.dll file errors
| Other Resources Other Support Sites
CommunityArticle Translations |





















Back to the top