Search code examples
vb.netregistrywildcard

VB.Net - Use wild card in My.Computer.Registry.GetValue


I have a VB.NET script that looks up the current version of java installed. Everything worked great until java 8 came out.

Back in Java 7 i would do this.

My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment", "Java7FamilyVersion", Nothing)

In Java 8 (Java8FamilyVersion) is gone and has replaced with (FullVersion). The problem is FullVersion is behind two more folders one with the version (18.0_25) Then another folder call MSI

So here is the problem; right now the first folder is called 18.0_25, but in the future it would be changed to something like 18.0.55ish.

I can't update my software that often, so i would like to use a wilcard in the getvalue IE something like this

My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\1.8.*\MSI", "FullVersion", Nothing)

Above didn't work is their anything that would work?


Solution

  • Use the GetSubKeyNamesmethod to enumerate the subkey(s) of "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment", then pick the alphabetically last (so that you do not fall for any old 1.7_xx keys or the 1.8 key)