Elencare gli applicativi installati tramite WMI

Uno snippet per elencare gli applicativi installati su un pc.

 

Dim path As New System.Management.ManagementPath(“root\cimv2”)
Dim options As New System.Management.ConnectionOptions

 

‘Local Host
path.Server = “.”

 

‘Remote Host
‘path.Server = “ServerName”
‘options.Username = “DomainName\UserName”
‘options.Password = “UserPassword”

 

Dim scope As New System.Management.ManagementScope(path, options)
Dim query As New System.Management.ObjectQuery(“SELECT * FROM Win32_Product”)
Dim search As New System.Management.ManagementObjectSearcher(scope, query)
Dim objectCollection As System.Management.ManagementObjectCollection

objectCollection = search.Get()

 

For Each myObject As System.Management.ManagementObject In objectCollection
       Console.WriteLine(myObject.GetPropertyValue(“Caption”))
Next