Click here to Skip to main content
Click here to Skip to main content

Programmatic administration of COM+ Applications with the COM+ Admin objects in VC++

By , 25 Jan 2001
Rate this:
Please Sign up or sign in to vote.
<!-- Download Links -->
  • Download demo project - 50 Kb
  • <!-- Main HTML starts here -->

    Introduction

    I started exploring programmatic administration of COM+ applications when we came across the requirement of changing the component’s constructor string via an MMC snapin as well as allow the flexibility to add a predetermined set of roles and allocate users to them at one shot via some installation script.

    The project involved a typical WinDNA application with COM+ components holding the business logic in the middle tier. A setup application installed the COM+ application with the components and all their attributes.

    Typically every COM+ application has the following configurable parameters of which some could be set through the component services tool and some can’t : (For details refer MSDN/ Platform SDK/Component Services/COM+/Reference/COM+ Administrator’s Reference)

    • AccessChecksLevel
    • Activation
    • ApplicationAccessChecksEnabled
    • ApplicationProxy
    • ApplicationProxyServerName
    • Authentication
    • AuthenticationCapability
    • Changeable
    • CommandLine
    • CreatedBy
    • CRMEnabled
    • CRMLogFile
    • Deleteable
    • Description
    • EventsEnabled
    • ID
    • ImpersonationLevel
    • Identity
    • IsSystem
    • Name
    • Password
    • QueuingEnabled
    • QueueListenerEnabled
    • RunForever
    • ShutdownAfter
    • 3GigSupportEnabled

    For individual Components in the application following parameters are configured:

    • AllowInprocSubscribers
    • ApplicationID
    • CLSID
    • ComponentAccessChecksEnabled
    • COMTIIntrinsics
    • ConstructionEnabled
    • ConstructorString
    • CreationTimeout
    • Description
    • DLL
    • EventTrackingEnabled
    • ExceptionClass
    • FireInParallel
    • IISIntrinsics
    • IsEventClass
    • JustInTimeActivation
    • LoadBalancingSupported
    • MaxPoolSize
    • MinPoolSize
    • MultiInterfacePublisherFilterCLSID
    • MustRunInClientContext
    • ObjectPoolingEnabled
    • ProgID
    • PublisherID,
    • Synchronization
    • ThreadingModel
    • Transaction
    • VersionBuild
    • VersionMajor
    • VersionMinor
    • VersionSubBuild

    The complete list for other related collections like Roles, RolesForComponent, etc could be found in the Platform SDK doc.

    A programmatic approach to configure all the above parameters is provided via the COM+ administration objects.

    The administration objects provide a way to access and manipulate all of the COM+ configuration data otherwise accessible through the Component Services administration tool. You can use these objects to automate all tasks in COM+ administration. These admin objects let us read and write information stored on the COM+ catalog, the underlying data store that holds all COM+ configuration data.

    Throughout MSDN and the platform SDK there was no sample code available for VC++ developers (at least I couldn’t find any) So I decided to write one.

    Visual studio doesn’t come with the header files or IDL files for COMAdmin.dll. So it isn’t as easy as including the header file in your project and getting to work with CoCreateInstance for the appropriate interface on the appropriate coclass.

    The COM+ 1.0 Type Library in OLEVIEW looks something like this.

    What I found was that The COM+ admin objects consists of three components (coclasses in IDL). Each of them having one main dispinterface as the default interface (as each coclass implemented one interface only). For example the coclass COMAdminCatalog implemented one interface ICOMAdminCatalog.

    coclass COMAdminCatalog {                     
    	[default] interface ICOMAdminCatalog;
    }; 

    This component represents the COM+ Catalog Manager.

    The reason I guess these components exposed dispinterfaces were because they needed to be accessed via installation scripts run under WSH or through VB.

    Talking more about the objects, There are logical collections such as Applications, Components and Roles which map to COMAdminCatalogCollection component. Similarly logical collections like Application, Component and Role map to the COMAdminCatalogObject component. The COMAdminCatalog stands as the root object and it contains the Applications Collection. The Roles and the Components collection could be retrieved from the Applications collection. Similarly the other collections specific to a component say "RolesForComponent" could be retrieved from the Components collection.

    Did I hear ‘yukss’ when I said dispinterfaces. Gosh!! Isnit that a pain to program in C++ - GetIdOfNames, DISPIDS, Invoke.

    VB developers never have to deal with raw VARIANT structures, setting discriminants, calling SysAllocString to allocate BSTR's. But in C++ we have to!

    Does that mean it is difficult to code COM+ admin objects in C++?

    NO ! the sample code uses the #import directive to incorporate information from the COM+ admin type library.

    The sample is a simple Win32 application. With a little smart pointer code, the code looks similar to VB code. Smile | :)

    All you gotta say is

    #import "c:\\winnt\\system32\\com\\Comadmin.dll"  no_namespace

    The no_namespace directs the compiler not to generate the type library information in a namespace, and hence contents like Interface names need not be be prefixed with the namespace::

    There, and you are all set to use the components without ever knocking on IUnknown's door. All the AddRef(), Release() and QueryInterface happen silently.

    For example:

    ICOMAdminCatalogPtr spCatalog("COMAdmin.COMAdminCatalog"); 

    The above call is translated to a CoCreateInstance call for the COMAdminCatalog component and a pointer to the interface is retrieved.

    The rest of the code is similar to VB.

    The sample does the following

    • Creates a HelloWorld COM+ Application called "HelloWorld",
    • Installs a HelloWorld component in to the application,
    • Sets the different Roles that the application might need,
    • Sets the roles explicitly for every component(one in this case)
    • Sets the ConstructorString for the component.

    I have included a sample VB activeX dll project HelloWorld.vbp which exposes a method, you could replace that with your own component if you wish to. Change the default value of the #defines if you wish to override default values for the HelloWorld application, especiallythe value of the HELLOWORLD_DLL_PATH to reflect the path where the VB Sample DLL is located.

    Please change the path of the component in the #define to reflect the path of the component you wish to include in the COM+ application

    Please find attached the demo project with the HelloWorld VB component, that could be used to add to the COM+ application.

    This article is a result of my experiences with the programming of COM+ admin objects. I assume that the application will be running under adequate user rights.

    If the code works, its written by me, or I don’t know who wrote it.

    References:

    • Platform SDK documentation,
    • Ted Pattison's article on COM+ admin objects on MSDN.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Ranjeet Chakraborty
    Web Developer
    United States United States
    I am originally from Mumbai, India, Currently living in Los Angeles doing Software Development. If there is something I miss here in LA, its the crazy Mumbai monsoon and delicious "wadapavs".
    Apart from spending time writing software, I spend most of my time with XBox riding the Warthog and killing covenants in Halo.

    Comments and Discussions

     
    GeneralCOM and COM+ Pinmembersaurabh.surana30-Mar-10 23:14 
    QuestionStart Stop a DTC Trace programmatically? Pinmemberrreukema20-Jul-09 16:07 
    QuestionDon't work under Windows 2000/2003 PinmemberAANru11-Mar-07 23:22 
    I have problem under Windows 2000/2003
    Creating COM+ Application - OK
    InstallComponents - Filed Frown | :( but under XP all work.

    QuestionHow to set Security properties PinmembernewWhiz23-Jan-04 17:10 
    Generaldegugging MTS component Pinmemberakshya24-Sep-03 20:44 
    GeneralAdmin properties... PinmemberJames31-Jan-01 16:36 
    GeneralRe: Admin properties... PinmemberRanjeet31-Jan-01 17:12 
    GeneralRe: Admin properties... PinmemberJimboe19-Feb-01 18:39 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140415.2 | Last Updated 26 Jan 2001
    Article Copyright 2001 by Ranjeet Chakraborty
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Use
    Layout: fixed | fluid