【转】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();
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值