views:

1045

answers:

2

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.

A: 

I have no experience with this particular property, but it seems to be documented in MSDN.

Arnout
+1  A: 

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.

Andrew J. Brehm
Just a few remarks, without knowing the object model in detail... 1. Initialize appId to null. 2. Use 'break' to exit the for loop once you've found your app. 3. Put 'if (appId != null)' around subsequent code. 4. components.SaveChanges() can probably be outside of the foreach loop.
Arnout