[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
Re: [2005] Improving speed of WMI calls
It's hard to make code better if you haven't seen the code.
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
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.
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. :)