簡體   English   中英

注冊表檢查路徑/密鑰是否存在

[英]Registry checking if path/key exists

嘿伙計們,快速愚蠢的問題......

我得到了這段代碼:

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,所以我想顯示它,即使密鑰丟失。

謝謝!

謝謝,山姆。 我確實發現了一些東西,不確定它是否會在某一時刻失敗......

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);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM