views:

124

answers:

0

AA,

I want to add a custom property to a WMi Object's Propert Collection. So that whenever i retrieve the properties of that object, i get the custom added property as well. Specifically speaking lets see the following code.

foreach (ManagementObject WebSite in WebSitesCollection)
        {
            if (WebSite.Properties["Name"].Value.ToString().Contains(appPoolName))
            {
                foreach (PropertyData propertyData in WebSite.Properties)
                {
                    try
                    {

                        HttpContext.Current.Response.Write(propertyData.Name + "  " + propertyData.Value + "<br/>");
                        if (propertyData.Name.Equals("Enable32BitAppOnWin64"))
                        {
                            AppPoolx.SetPropertyValue("Enable32BitAppOnWin64", true);
                            AppPoolx.Put(); return true;
                        }
                        else
                        {
                         AppPoolx.Properties.Add("Enable32BitAppOnWin64", true);
                          AppPoolx.Put(); return true;
                        }

                    }
                    catch (Exception ex1)
                    {
                        HttpContext.Current.Response.Write("Error Ocurred while Setting Property: " + ex1.Message + "<br />");
                        break;
                    }
                }
            }

        }

But the AppPoolx.Properties.Add("Enable32BitAppOnWin64", true); returns error

Operation is not valid due to current state of the object.

I was wondering whether it was even possible to add a custom property to the WMi object. If what is this Add() function for?

In any case, what is the correct procedure of add a "Custom Property to a WMI Object."

Please do not suggest that i may store in DB.

Regards

Steve