我收到了这段代码:
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");
哪个字符串指向已安装应用程序的路径,但如果注册表不存在,我的程序将停止。 我如何检查注册表是否存在以及是否不绕过它?
如果密钥不存在,还可以添加system.err.println("Application not installed.");
。
PS:程序是一个GUI,所以我想显示它,即使密钥丢失了。
谢谢!
答案 0 :(得分:0)
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);
}
}