OK, it is the WMI Code Creator doing something to activate or initiallize the counters. The counters start having data in them after I click "Search for Property Values." I took a look at the code for the WMI Code Creator and it looked almost exactly like mine, but I changed mine to use the same constructors for ManagementObjectSearcher with no luck.
What do you guys think? Should the counters need to be activated or initiallized? Or should I be able to access them and get valid data? In other words, should the following code provide data?
m_managObjSearch =
ManagementObjectSearcher(new ManagementScope("root\\CIMV2"), new WqlObjectQuery("SELECT * FROM Win32_PerfFormattedData_W3SVC_WebService"), null);
foreach (ManagementObject service in m_managObjSearch.Get())
{
Object tmpPropertyValue = service["ServiceUptime"];
if (tmpPropertyValue != null)
{
context.Response.Write("ServiceUptime: " + tmpPropertyValue);
}
}
Sincerely,
Matt