Search code examples
.netcomponentscom+

How do I check "Allow IIS intrinsic properties" in a COM+ application programmatically?


Component Services -> Computers -> My Computer -> COM+ Applications

Open a COM+ Application object.

Open Components.

Right-click on a class and select Properties.

Under "Advanced" there is a check box for "Allow IIS intrinsic properties".

How do I check this check box programmatically?

I can create and delete COM+ Applications programmatically, but the ComApplication class doesn't seem to have ways to change settings in the created application.


Solution

  • I found out how to do it.

    Apparently I have to get a collection of COM+ applications, find the one I want (by name), then get a collection of components in the application, then go through the collection and set the attribute:

                //get collection of applications
            COMAdminCatalog catalog = new COMAdminCatalog();
    
            catalog.Connect("127.0.0.1");
    
            COMAdminCatalogCollection applications = (COMAdminCatalogCollection)catalog.GetCollection("Applications");
    
            applications.Populate(); //no idea why that is necessary, seems to be
    
            // appId for the application we are looking for
            object appId = new object();
    
            int count = applications.Count;
            ICatalogObject item;
    
            if (count == 0) return;
    
            //search collection for item with name we are looking for
            for (int i = 0; i < count; i++)
            {
    
                item = (ICatalogObject)applications.get_Item(i);
    
                if (applicationName == (string)item.get_Value("Name"))
                {
    
                    appId = item.Key;
    
                    Console.WriteLine("appId found for " + applicationName + ": " + appId.ToString());
    
                }
    
            }
    
            // get all components for the application
            COMAdminCatalogCollection components;
    
            components = (COMAdminCatalogCollection)applications.GetCollection("Components", appId);
            components.Populate(); // again, no idea why this is necessary
    
            // set the attribute in all components
    
            foreach (COMAdminCatalogObject component in components)
            {
    
                Console.WriteLine("Setting IISIntrinsics attribute in " + component.Name + ".");
                component.set_Value("IISIntrinsics", true);
                components.SaveChanges();
    
            }
    

    I think this can be done better and with fewer castings. But I don't know how.

    This will do.