gpt4 book ai didi

java - 注册表检查路径/键是否存在

转载 作者:太空宇宙 更新时间:2023-11-04 12:10:36 25 4
gpt4 key购买 nike

嘿伙计们,愚蠢的问题......

我得到了这个代码:

String arch = System.getenv("PROCESSOR_ARCHITECTURE");
String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");
String realArch = arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64") ? "64" : "32";
String setWin = ((realArch.contains("64")) ? "SOFTWARE\\Wow6432Node\\path" : "SOFTWARE\\path");
String check = Advapi32Util.registryGetStringValue (HKEY_LOCAL_MACHINE, setWin, "InstallDir");

它字符串是已安装应用程序的路径,但如果注册表不存在,我的程序就会停止。我如何检查注册表是否存在以及是否没有绕过它?

如果 key 不存在,还要添加system.err.println("Application notinstalled.");

PS:该程序是一个 GUI,所以即使 key 丢失我也想显示它。

谢谢!

最佳答案

谢谢你,山姆。我确实发现了一些东西,不确定它是否会在某一时刻失败......

public void checkInstalled(){
try {
String regValue = null;
regValue = WinRegistry.valueForKey(WinRegistry.HKEY_LOCAL_MACHINE, setWin, "InstallDir");
if(regValue == null){
System.err.println("Application not installed!");
} else {
"do the other thing"
}
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | IOException ex) {
System.err.println(ex);
}
}

关于java - 注册表检查路径/键是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39895848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com