
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