In-process Servers and DCOMCNFG Utility

Environment: VC 6.0 w/ sp3, NT 4.0 w/ sp4.

In-process servers can never run without a parent process. Period. However, since the release of Windows NT 4.0 Service Pack 2, in-process servers can be remoted as long as a surrogate is available to provide the needed address space. One such surrogate is the file <dllhost.exe> that can be remoted and then instructed to load any in-process component, providing the component with a surrogate parent process and security context. But how do you set security permissions, identity, client's authentication level, and the set of protocols and endpoints for use by clients for such an in-process component? One easy way of setting this up is to use DCOMCNFG utility. However, by default DCOMCNFG utility won't list components housed in in-process servers. It will list only component executables registered on the system.

Run OLEViewer and select any in-process DLL server object. Select the Implementation tab, and select the Use Surrogate Process check box. Select the Registry tab (this will add the DllSurrogate named value under the AppID key). Provide a path to custom surrogate or the default <..\winnt\system32\dllhost.exe> surrogate.

Now run the DCOMCNFG utility. The in-process DLL server object will show up in the list of applications. Basically, we convinced the DCOMCNFG utility that the in-process DLL server object is no longer alone and that it has a parent process where it will be housed when it is remoted.

Example project:

1. Choose ATL COM AppWizard and DLLSurr as name of the project. Be sure to select the Server type as Dynamic Link Library (DLL).
2. Add a new ATL object with a short name ATest.

Build and register the server. Select the component ATest in OLEViewer (Object Classes->All Objects->ATest). Select the Implementation tab, and select the Use Surrogate Process check box. Select the Registry tab (this will add the DllSurrogate named value under the AppID key). Provide a path to the default surrogate as <..\winnt\system32\dllhost.exe>. Now run DCOMCNFG and select ATest. Choose Properties, Security, and edit Use custom access permissions and select an NT user name (for demo purpose, you may want to choose your NT user name). Select Deny access from the Type of Access combo box. Click OK all the way to close the DCOMCNFG utility.

Client code to launch the server:

#include "stdafx.h"
#include <comdef.h>
#import "..\DLLSurr.tlb" no_namespace named_guids

{
    // This block of code assumes that you have already
    // initialized COM libraries somewhere in your project.

    try
    {
        // For demo purpose, assume that the component is
        // launched on a local m/c.

        // Try to inject the component server into dllhost.exe's
        // address space
        IATestPtr ptrTest = NULL;
        HRESULT hr = ptrTest.CreateInstance(CLSID_ATest,
                NULL, CLSCTX_LOCAL_SERVER /*This flag is important*/);
        if(FAILED(hr))
        {
            TRACE("Failed to create ATest component.\n");
            _com_issue_error(hr);
        }
    }
    catch(_com_error& e)
    {
        TRACE(e.ErrorMessage() + _bstr_t("\n")); // Probably, the trace should
                                                 // be <Access is denied>!
        if(e.ErrorInfo())
            TRACE(e.Description() + "\n");
    }

    // If you see the processes list in the Task Manager,
    // you will find dllhost.exe sitting there. Kill that
    // process before you change any security settings in
    // the DCOMCNFG utility for the component.
}

Alternatively, you can also test the server in OLEViewer. From the menu, choose Object...CoCreateInstance flags, select CLSCTX_LOCAL_SERVER and deselect all other items. Right click on the component name and choose <Create Instance On...>.

Conclusion:

This article discussed DLL surrogates briefly and how legacy in-process components can participate in a distributed environment.

It is interesting to note that Microsoft SQL Server extended procedures (which are nothing but DLLs) runs in SQL Server address space and that a badly behaved extended stored procedure could crash SQL Server.

References:

1. Inside Distributed COM, Guy Eddon and Henry Eddon, Microsoft Press 1998.
2. MSDN Library April



Comments

  • Request for Proposal and Request for Information

    Posted by Legacy on 03/24/2003 12:00am

    Originally posted by: Sanjay S Srivatsa

    What is a Request for Proposal and Request for Information in terms of Systems Analysis and Design ?

    Reply
  • DCOMCNFG Settings

    Posted by Legacy on 11/19/2001 12:00am

    Originally posted by: Scott Vickery

    I have a COM app that I wrote in Delphi, and the server app was also written in Delphi. I have both programs on a remote machine. Problem is, when I run the program, it works fine... infact, it seems to work for anyone with Admin rights. I've loaded DCOMCNFG and added the domain users group so they all have full control of lauching/controlling the Server app. For some reason, it still doesn't work for these other users?

    Any ideas ?????

    The client machines are Windows 95 and Windows 98 predominately but some NT and Win2k machines will also be on the network.

    Reply
  • Using RSH to run a program with COM object

    Posted by Legacy on 01/21/2001 12:00am

    Originally posted by: Tina McDaniel

    I use 'remote shell' to start a program that exists on another PC.
    That program named 'test.exe'. It has COM object, and that works fine on its own PC.

    rsh MACHINENAME c:\test.exe

    The exception occurs on line RegisterClassObjects() - registering the class factory. What do I need to do????
    Thanks.

    BOOL CRASvrThread::InitInstance()
    {
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    _ASSERTE(SUCCEEDED(hRes));

    if (FAILED(hRes))
    {
    // Log error
    }
    else
    {
    m_bCoInitialized = TRUE;

    hRes = _Module.RegisterClassObjects (CLSCTX_SERVER, REGCLS_MULTIPLEUSE);
    _ASSERTE(SUCCEEDED(hRes));

    Reply
  • I can't find the dcomcnfg.exe utility on the windows98 machine !!! ?

    Posted by Legacy on 11/07/2000 12:00am

    Originally posted by: Deepa

    I have a DCOM component that has to be hosted on a windows98 machine.I want to set the security settings for this component but i find that the dcomcnfg.exe is not available on my win98 machine !
    Does one need to install this utility separatley or what...?
    Does the dcomcnfg utility differ for NT and 98 ?
    What is the exact use of dcom98.exe ?

    Reply
  • What is Executable COM?

    Posted by Legacy on 10/31/2000 12:00am

    Originally posted by: huahuang

    Hi!
    I am learning COM/DCOM now using ATL wizard.
    Please tell when I should choose Executable(EXE) as the Server Type? What is Executable COM?
    Thank you.

    Reply
  • Can this method be used under Win98?

    Posted by Legacy on 07/21/1999 12:00am

    Originally posted by: lurui

    I used it under Win98. It always message a box that says "No system message defined" when I used cocreated on...

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds