Results 1 to 5 of 5

Thread: [2005] Improving speed of WMI calls

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    45

    Question [2005] Improving speed of WMI calls

    Hello everyone,

    I am still learning how to integrate wmi into vb.net,
    I was able today to write a program which can retrieve installed software from a remote computer. The issue is that the process took over 30 seconds which is some how high.
    Is there any technique to improve this ?

    Thank you
    Best Regards

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Improving speed of WMI calls

    It's hard to make code better if you haven't seen the code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    45

    Re: [2005] Improving speed of WMI calls

    Quote Originally Posted by jmcilhinney
    It's hard to make code better if you haven't seen the code.
    Sorry for that, the program is still very simple and i am using it for testing.
    The program should retrieve the list of installed software.

    Code:
    Imports System.Management
    
    Module Module1
    
        Sub Main()
            Dim myconnectionoptions As New System.Management.ConnectionOptions
            With myconnectionoptions
                .Impersonation = ImpersonationLevel.Impersonate
                .Authentication = AuthenticationLevel.Packet
            End With
    
          
            Dim managementscope As System.Management.ManagementScope
    
            managementscope = New System.Management.ManagementScope("\\192.168.1.3\root\cimv2", myconnectionoptions)
            managementscope.Connect()
    
            If managementscope.IsConnected = True Then
                Console.WriteLine("Connection Established")
               
            Else
                Console.WriteLine("COULD NOT CONNECT")
            End If
    
     
            Dim myobjectsearcher As System.Management.ManagementObjectSearcher
            Dim mycollection As System.Management.ManagementObjectCollection
            Dim myobject As System.Management.ManagementObject
            myobjectsearcher = New System.Management.ManagementObjectSearcher(managementscope.Path.ToString, "Select * from Win32_Product") 'Win32_Product
            mycollection = myobjectsearcher.Get
    
            For Each myobject In mycollection
                Console.WriteLine(myobject.GetPropertyValue("Caption"))
            
            Next
    
            Console.ReadLine()
    
        End Sub
    
    End Module
    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Improving speed of WMI calls

    You should step through the code one line at a time and see what parts take a long time. You can also time each step and output the results to the Output window or a log file or whatever. You can't always fix code by looking at it. Just like a machine you have to run it and analyse its performance in action.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    45

    Re: [2005] Improving speed of WMI calls

    The part taking the most time is when you query the machine for the installed software. So I think u mean its not the code that is slow but the querying process and retrieving the data..
    I tried to query a machine with 30+ programs so maybe thats why it took sometime.
    Thanks jmcilhinney.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width