1,读取一个键值
String value = WinRegistry.readString ( WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName"); System.out.println("Windows Distribution = " + value);
在我的机器上的输出是
引用
Windows Distribution = Windows 7 Ultimate
2,遍历某个目录下的若干小目录,这里只打印目录名字
String path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; Listsubs = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE, path); for (String s : subs) { System.out.println(s); }
3,写一个值也很简单
WinRegistry.writeStringValue ( WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "TestKey", "TestValue");