0

I am trying to put together some VB code that will query WMI at Win32_Product for installations of Java and then return its version number.

For example:

Java data in programs and features:

Name - Java 8 Update 91 (64-bit)
Version - 8.0.910.14

I would want this query to return the Version information so that I could populate a textbox/label/listbox with it.

Here is what I have so far:

Dim strComputer = "."
Dim objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Dim colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where Name ='Java 8 Update 91 (64-bit)'")
For Each objItem In colSoftware
    ListBox1.Text = ("Version: " & objItem.Version)
Next

This code doesn't show any errors in Visual Studio, but when I try to run it, it doesn't populate my listbox.

Any ideas?

PS: I am not much of a developer I am working on this to participate in a hackathon at work. So please excuse if this doesn't make much sense.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Change
  • 11
  • 3
  • 1
    Is this VB.net or VBScript? They're different languages. Also, note that [`Win32_Product` is considered evil](https://gregramsey.net/2012/02/20/win32_product-is-evil/). – Ansgar Wiechers Oct 24 '17 at 00:11
  • Try this code in simple Console Application and see if it works. – Ondřej Oct 24 '17 at 06:06

0 Answers0