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
java改_用Java修改系统的环境变量
最新推荐文章于 2024-07-12 21:52:53 发布