Posted by Adam Buenz
I totally didn't know that there was a ManagementObjectEnumerator class, but I found out there was today which made me all sorts of happy. What I was trying to do was to just display a list of the application pools of the current host machine's IIS instance within this small WinForms app I have that performs some warm-up functions for SharePoint. I needed to target application pools because we have a complex recycling theme, and I needed scheduled post-warm up functions. What I ended up doing in order to list them was just this:
C#:
-
string l_strClassPath = @"\\" + hostname + @"\root\microsoftiisv2:IIsApplicationPoolSetting";
-
{
-
using (ManagementObjectCollection.ManagementObjectEnumerator l_oMoEnumerator = l_oWmi.GetInstances().GetEnumerator())
-
{
-
while (l_oMoEnumerator.MoveNext())
-
{
-
ManagementObject l_oChildMO = ((ManagementObject)l_oMoEnumerator.Current);
-
char[] l_aSplitChar = "/".ToCharArray();
-
tbApplicationPoolList.Items.Add(l_oChildMO.ToString().Split(l_aSplitChar)[(l_oChildMO.ToString().Split(l_aSplitChar).Length - 1)].Replace("\"", ""));
-
}
-
}
-
}
I like that!











November 14th, 2007 at 3:48 pm
You do realize that lines 4 through 7 can be exactly replaced by:
foreach (ManagementObject l_oChildMo in l_oWmi.GetInstances()) {
?