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

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:46:36

问题


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?


回答1:


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)




回答2:


You could grab a file version from one of the Java .dll files. Sorry, I don't have Java installed, but something like this might help you:

Dim fvi As FileVersionInfo = FileVersionInfo.GetVersionInfo("somefilename.dll")
Debug.Print(fvi.ProductVersion)

You can fiddle with the returned properties for major, minor, etc. You should be able to build a version string to get what you need.



来源:https://stackoverflow.com/questions/26593347/vb-net-use-wild-card-in-my-computer-registry-getvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!