`
rmzdb
  • 浏览: 78563 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

【转】Java操作注册表信息 .

阅读更多
在代码开始前,我们先了解一下操作系统对对注册表的相关命令与操作

REG Operation [参数列表]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT ]

返回代码: (除了 REG COMPARE)

  0 - 成功
  1 - 失败

要得到有关某个操作的帮助,请键入:

  REG Operation /?

例如:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 * 
 * @description 本程序实现了读取注册表分支:HKEY_CURRENT_USER/Software/ODBC/ODBC.INI/ODBC Data Sources到内存的操作
 */
public class getRegToMemery {
	public static void main(String []args){
		try {
			Process ps = null;
			ps = Runtime
					.getRuntime()
					.exec(
							"reg query /"HKEY_CURRENT_USER//Software//ODBC//ODBC.INI//ODBC Data Sources/"");
			ps.getOutputStream().close();
			InputStreamReader i = new InputStreamReader(ps.getInputStream());
			String line;
			BufferedReader ir = new BufferedReader(i);
			while ((line = ir.readLine()) != null) {
				System.out.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics