java改_用Java修改系统的环境变量

1 packageframe;2 3 importjava.io.BufferedReader;4 importjava.io.InputStreamReader;5 6 importcom.ice.jni.registry.RegStringValue;7 importcom.ice.jni.registry.Registry;8 importcom.ice.jni.registry.RegistryKey;9 10 publicclassTestRegistry {11 12 /**13 *@paramargs14 */15 publicstaticvoidmain(String[] args) {16 //TODO Auto-generated method stub17 try{18 //RegistryKey openPath119 //= Registry.HKEY_LOCAL_MACHINE.openSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment");20 //String path_Old = openPath1.getStringValue("PAODING_DIC_HOME");//获取原Path键值21 //System.out.println(path_Old);22 //System.out.println(System.getProperty("user.dir"));23 24 RegistryKey openPath225 =Registry.HKEY_LOCAL_MACHINE.openSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager");26 RegistryKey subKey=openPath2.createSubKey("Environment","");27 subKey.setValue(newRegStringValue(subKey,"PAODING_DIC_HOME","D:\\PaodingEnv\\Dic"));//修改Path键值28 subKey.closeKey();29 /*RegistryKey openPath230 = Registry.HKEY_LOCAL_MACHINE.openSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager");31 32 RegistryKey subKey = openPath2.createSubKey("Environment", "");33 //定义Path所在目录的句柄(相当于在Session Manager路径下面,新建Environment文件夹,如果存在不改变已有的值。)34 //   String path_New = path_Old + ";" + "D:\\myTinoProject\\bingy";35 String path_New = path_Old + "bin;";36 subKey.setValue(new RegStringValue(subKey, "Path", path_New)); //修改Path键值37 subKey.closeKey();38 //查看进程的方法39 String[] cmd = { "D:\\dfqd\\workspace\\tasklist" };40 Process proc = Runtime.getRuntime().exec(cmd);41 BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));42 String string_Temp = in.readLine();43 while (string_Temp != null) {44 System.out.println(string_Temp);45 string_Temp = in.readLine();46 }47 //删除explorer.exe进程48 Process proc2 = Runtime.getRuntime().exec("D:\\dfqd\\workspace\\taskkill /F /IM explorer.exe");49 Thread.sleep(500);50 //重启explorer.exe进程51 Process proc3 = Runtime.getRuntime().exec("explorer.exe");52 System.out.println("=====SUCCESS=====");*/53 }54 catch(Exception e) {55 e.printStackTrace();56 }57 }58 }59

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值