INFO: COM Servers Activation and NT Windows StationsLast reviewed: November 21, 1997Article ID: Q169321 |
The information in this article applies to:
SUMMARYWhen 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 INFORMATIONWhen 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.Under Windows NT, each window station has at least one desktop associated with it. Windows NT uses a special memory heap for all windows applications running on a desktop. By default, each desktop heap consumes 3MB of memory. Windows NT has a non-configurable limit of 48MB for creating desktop heaps. This means that the maximum number of window stations that can be created on a Windows NT machine is 16 (probably less because a window station can contain more than one desktop). To increase this number, you can reduce the default desktop heap size by editing the registry using the Registry Editor. 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\SubSystemsYou need to edit the "Windows" named value. It is a REG_SZ string. Edit the string and look for "Shared Section=1024,3072". Modify this to read "Shared Section=1024,3072,512". You need to restart the machine for this change to take effect. By making this change, you are specifying 3MB (default) heap size for the interactive window station's desktop and 512 KB for all non- interactive desktops (the first parameter is obsolete but should not be changed). This change will allow the creation of approximately less than 48MB/512KB or 96 window stations. 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.
REFERENCESFor additional information about the desktop heap issue, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142676 TITLE : Overcome User32.dll Initialization Failure Errors Keywords : BseSecurity kbenv kbinterop kbprg kbusage Technology : kbole Version : 4.0 Platform : NT WINDOWS Issue type : kbinfo |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |