ManagementClass.GetInstances() takes a long time

G

Guest

I am calling the method GetInstances() within the ManagementClass. I have 48
applications on my system. Mearly calling the routine takes 28 seconds for
it to return. I don't understand why this method would take so long to
execute. I've tried setting the EnumerationOptions.EnumerateDeep to false
but it doesn't seem to have any impact on the time. Can someone tell me how
to speed up the execution of this method?
 
W

Willy Denoyette [MVP]

Steve Teeples said:
I am calling the method GetInstances() within the ManagementClass. I have
48
applications on my system. Mearly calling the routine takes 28 seconds
for
it to return. I don't understand why this method would take so long to
execute. I've tried setting the EnumerationOptions.EnumerateDeep to false
but it doesn't seem to have any impact on the time. Can someone tell me
how
to speed up the execution of this method?

Mnd to tell us what instances your are trying to retrieve?

Willy.
 
G

Guest

Win32_Product.

I used the wbemtest.exe tool also just to see if my code somehow was slowing
it down and I see the same results with it. If you pull up all instances of
Win32_Product (I have 38 apps installed) it takes about 30 seconds for the
call to return. I'm iterating through many Win32_xxx classes and some of
these cause a massive delay in my app. I'm hoping to avoid the delay.
 
G

Guest

Here is a snipit of my code.

ManagementClass aClass = new ManagementClass(className);
if (aClass != null)
{
aClass.Scope = new ManagementScope(this.cimScope);
EnumerationOptions opts = new EnumerationOptions();
opts.EnumerateDeep = false;
opts.ReturnImmediately = false;
ManagementObjectCollection instances = aClass.GetInstances(opts);
foreach (ManagementObject instance in instances)
{
... doing a string manipulation ...
}
}
 
W

Willy Denoyette [MVP]

Ok I see "Win32_Product", this is indeed a slow operation when executed the
first time.
WMI first retrieves a basic list of the installed products (using MSI), from
the "msi install server", and uses each item in the list to scan the
registry for product details, for this WMI has to map large portions of the
registry and that takes time. Once the services are running and the registry
portions are mapped the query returns somewhat faster, but this isn't of
great help of course.
I really don't see a way to speed up these queries the way it's designed.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top