2012-02-22 50 views
0

我正忙於創建一個程序,該程序將讀取註冊表的各個部分,以瞭解USB設備已連接到Windows系統等...我已經設法創建一個的軟件會顯示什麼值,但是每個人的註冊表都會保存不同的信息。在註冊表中讀取子文件夾(JAVA)

我試過尋找無處不在尋找幫助/ guidence代碼能夠掃描註冊表文件夾並顯示其中的子文件夾。我知道有很多用於閱讀普通文件位置的代碼,但是沒有人會嘗試讀取註冊表。

我試圖讀取該文件夾的位置是:

「\」 HKLM \系統\ CurrentControlSet \枚舉\ USBSTOR \

我已經成功地創建一個程序,它會讀取值從上述位置,但我必須手動指定每個子文件夾到代碼中。

我希望我已經解釋了什麼是我需要的,如果對不起它的提前混亂

感謝

+0

可能[使用Java讀取/寫入Windows註冊表]的副本(http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java) – 2012-02-22 21:56:32

回答

0

我用jRegistryKey.dll jRegistryKey.jar 在這裏你去 ftp://ftp.heanet.ie/mirrors/sourceforge/j/project/jr/jregistrykey/manual/original/jreg_key.pdf

例如代碼:

import ca.beq.util.win32.registry.RegistryKey; 
import ca.beq.util.win32.registry.RegistryValue; 
import ca.beq.util.win32.registry.RootKey; 

從例如枚舉---

RegistryKey r = new RegistryKey(RootKey.HKEY_CURRENT_USER, "Software"); 
if(r.hasSubkeys()) { 
    Iterator i = r.subkeys(); 
    while(i.hasNext()) { 
     RegistryKey x = (RegistryKey)i.next(); 
     System.out.println(x.toString()); 
    } // while 
} // if 

  RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, "Software\\app\\update\\Date"); 
      if (r.hasValue("LastSuccessfulUpdate")) { 
      RegistryValue v = r.getValue("LastSuccessfulUpdate"); 
      updateDate = v.getStringValue(); 
      Date now = new Date(Long.parseLong(updateDate.trim() + "000")); 

................ }