資源簡介
詳情請參考http://blog.csdn.net/a8_8a/article/details

代碼片段和文件信息
package?registryCut;
import?java.lang.reflect.InvocationTargetException;
import?java.util.List;
import?java.util.Map;
import?java.util.Map.Entry;
import?java.util.Set;
import?registryCut.util.WinRegistry;
public?class?RegistryCutTest?{
public?static?void?main(String[]?args)?throws?Exception?{
// Test1();
// Test2();
Test3();
}
/**
?*?在有權限的情況下獲取指定節點下所有的子節點
?*?
?*?@throws?InvocationTargetException
?*?@throws?IllegalAccessException
?*?@throws?IllegalArgumentException
?*?
?*?@throws?Exception
?*/
private?static?void?Test3()?throws?Exception?{
List?subKeys?=?WinRegistry.readStringSubKeys(
WinRegistry.HKEY_LOCAL_MACHINE
?“SOFTWARE\\Microsoft\\Windows?NT\\CurrentVersion“);
if?(subKeys?==?null)?{
System.out.println(“null1“);
return;
}
for?(int?i?=?0;?i? if?(subKeys.get(i)?==?null)?{
System.out.println(“空“);
}?else?{
System.out.println(subKeys.get(i));
}
}
}
/**
?*?獲取指定節點下指定key的value
?*?指定的節點是?HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows?NT\CurrentVersion
?*?指定的key是?ProductName
?*?
?*?@throws?IllegalArgumentException
?*?@throws?IllegalAccessException
?*?@throws?InvocationTargetException
?*/
private?static?void?Test1()?throws?Exception?{
String?value?=?WinRegistry.readString(WinRegistry.HKEY_LOCAL_MACHINE?//?HKEY
“SOFTWARE\\Microsoft\\Windows?NT\\CurrentVersion“?//?Key
“ProductName“);?//?ValueName
System.out.println(“Windows?Distribution?=?“?+?value);
}
/**
?*?獲取指定節點下所有的鍵值對
?*?指定的節點是?HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows?NT\CurrentVersion
?*?
?*?@throws?IllegalArgumentException
?*?@throws?IllegalAccessException
?*?@throws?InvocationTargetException
?*/
private?static?void?Test2()?throws?Exception?{
Map?m?=?WinRegistry.readStringValues(
WinRegistry.HKEY_LOCAL_MACHINE?//?HKEY
“SOFTWARE\\Microsoft\\Windows?NT\\CurrentVersion“);?//?ValueName
Set>?entrySet?=?m.entrySet();
for?(Entry?entry?:?entrySet)?{
System.out.println(entry.getKey()?+?“=“?+?entry.getValue());
}
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2259??2014-12-07?20:13??registryCut\RegistryCutTest.java
?????文件??????13099??2014-12-07?19:58??registryCut\util\WinRegistry.java
?????目錄??????????0??2014-12-07?20:16??registryCut\util
?????目錄??????????0??2014-12-07?20:16??registryCut
-----------?---------??----------?-----??----
????????????????15358????????????????????4
評論
共有 條評論