java 判断注册表是否存在,在Windows中使用Java查找特定的注册表项

I can go to regedit in windows then go to edit->find and type in the key I want to find in my computer (in my case Maxima) and locate the required key (of maxima) (in my case it is in "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Maxima-5.17.1_is1")

but I need to do this dynamically in java and find the current version of maxima installed and its directory location in windows. I have no idea how to proceed.

I tried to use the methods stated here: read/write to Windows Registry using Java, but to use these methods I need to know the key. How can I find the key dynamically in java? Or is there any other ways to find the version and directory location of a software in windows using java?

解决方案

I will use this class for your answer. Because it is written in pure java code.

Have a WinRegistry class from here.

Get a list of all keys in parent key.

filter list to get the most appropriate key (Or exact key).

Then you can check the value you want in this key.

Here is the code to help you :

List ls = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE,

"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");

String key = ls.stream().filter(st -> st.matches("Maxima.*")).findAny().get();

Now this key value will be Maxima-5.17.1_is1 (if present otherwise java.util.NoSuchElementException will be thrown). And you can use it to get any Value.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值