注册表检查路径/键是否存在 [英] Registry checking if path/key exists
本文介绍了注册表检查路径/键是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿伙计们,问个愚蠢的问题...
Hei guys, quick stupid question...
我得到了这个代码:
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");
哪个字符串是已安装应用程序的路径,但如果注册表不存在,我的程序将停止.我如何检查注册表是否存在以及是否不绕过它?
Which strings a path to a installed application, but if the registry doesn't exists my program stops. How i can check if the registry exists and if doesn't bypass it?
并添加 system.err.println("Application not installed.");
如果密钥不存在.
and also to add system.err.println("Application not installed.");
if the key doesn't exists.
PS:该程序是一个 GUI,所以即使密钥丢失我也想显示它.
PS: The program is a GUI so i want to show it even if the key is missing.
谢谢!
推荐答案
谢谢山姆.我确实找到了一些东西,不确定它是否会在某一时刻失败......
Thank you, Sam. I did found something, not sure if it will fail at one point ...
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);
}
}
这篇关于注册表检查路径/键是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文