资源简介
详情请参考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 < subKeys.size(); 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
川公网安备 51152502000135号
评论
共有 条评论