ManagementClass.GetInstances() takes a long time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Teeples

    ManagementClass.GetInstances() takes a long time

    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 EnumerationOpti ons.EnumerateDe ep 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?

    --
    Steve
  • Willy Denoyette [MVP]

    #2
    Re: ManagementClass .GetInstances() takes a long time


    "Steve Teeples" <SteveTeeples@d iscussions.micr osoft.com> wrote in message
    news:72E5DC5E-7F9A-4167-9A88-F129E0C04D4F@mi crosoft.com...[color=blue]
    >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 EnumerationOpti ons.EnumerateDe ep 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?
    >
    > --
    > Steve[/color]

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

    Willy.


    Comment

    • Steve Teeples

      #3
      RE: ManagementClass .GetInstances() takes a long time

      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.

      --
      Steve


      "Steve Teeples" wrote:
      [color=blue]
      > 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 EnumerationOpti ons.EnumerateDe ep 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?
      >
      > --
      > Steve[/color]

      Comment

      • Steve Teeples

        #4
        Re: ManagementClass .GetInstances() takes a long time

        Here is a snipit of my code.

        ManagementClass aClass = new ManagementClass (className);
        if (aClass != null)
        {
        aClass.Scope = new ManagementScope (this.cimScope) ;
        EnumerationOpti ons opts = new EnumerationOpti ons();
        opts.EnumerateD eep = false;
        opts.ReturnImme diately = false;
        ManagementObjec tCollection instances = aClass.GetInsta nces(opts);
        foreach (ManagementObje ct instance in instances)
        {
        ... doing a string manipulation ...
        }
        }

        --
        Steve


        "Willy Denoyette [MVP]" wrote:
        [color=blue]
        >
        > "Steve Teeples" <SteveTeeples@d iscussions.micr osoft.com> wrote in message
        > news:72E5DC5E-7F9A-4167-9A88-F129E0C04D4F@mi crosoft.com...[color=green]
        > >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 EnumerationOpti ons.EnumerateDe ep 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?
        > >
        > > --
        > > Steve[/color]
        >
        > Mnd to tell us what instances your are trying to retrieve?
        >
        > Willy.
        >
        >
        >[/color]

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: ManagementClass .GetInstances() takes a long time

          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.

          "Steve Teeples" <SteveTeeples@d iscussions.micr osoft.com> wrote in message
          news:5EEC2308-3B71-440A-9D88-592E9D03F9E2@mi crosoft.com...[color=blue]
          > 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.
          >
          > --
          > Steve
          >
          >
          > "Steve Teeples" wrote:
          >[color=green]
          >> 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 EnumerationOpti ons.EnumerateDe ep 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?
          >>
          >> --
          >> Steve[/color][/color]


          Comment

          Working...