2 package org.feistymeow.system;
21 public static boolean checkKey(String keyName) {
24 StringBuilder command =
new StringBuilder(QUERY_COMMAND);
26 command.append(keyName);
29 Process process = Runtime.getRuntime().exec(command.toString());
30 StreamReader reader =
new StreamReader(process.getInputStream());
34 return process.exitValue() == 0;
35 }
catch (Exception e) {
43 public static String
getValue(String keyName, String valueName, String typeExpected) {
46 StringBuilder command =
new StringBuilder(QUERY_COMMAND);
48 command.append(keyName);
50 command.append(VALUE_FLAG);
51 command.append(valueName);
53 Process process = Runtime.getRuntime().exec(command.toString());
54 StreamReader reader =
new StreamReader(process.getInputStream());
59 String result = reader.getResult();
60 int p = result.indexOf(typeExpected);
61 if (p == -1)
return null;
63 return result.substring(p + typeExpected.length()).trim();
64 }
catch (Exception e) {
72 public static boolean setValue(String keyName, String valueName, String typeExpected, String newValue) {
75 StringBuilder command =
new StringBuilder(SET_COMMAND);
77 command.append(keyName);
79 command.append(VALUE_FLAG);
80 command.append(valueName);
81 command.append(TYPE_FLAG);
82 command.append(typeExpected);
83 command.append(FORCE_FLAG);
84 command.append(DATA_FLAG);
85 command.append(newValue);
88 Process process = Runtime.getRuntime().exec(command.toString());
89 StreamReader reader =
new StreamReader(process.getInputStream());
93 return (process.exitValue() == 0);
94 }
catch (Exception e) {
100 public static boolean deleteValue(String keyName, String valueName) {
103 StringBuilder command =
new StringBuilder(DELETE_COMMAND);
104 command.append(
"\"");
105 command.append(keyName);
106 command.append(
"\"");
107 command.append(VALUE_FLAG);
108 command.append(valueName);
109 command.append(FORCE_FLAG);
112 Process process = Runtime.getRuntime().exec(command.toString());
113 StreamReader reader =
new StreamReader(process.getInputStream());
117 return (process.exitValue() == 0);
118 }
catch (Exception e) {
127 StringBuilder command =
new StringBuilder(DELETE_COMMAND);
128 command.append(
"\"");
129 command.append(keyName);
130 command.append(
"\"");
131 command.append(FORCE_FLAG);
134 Process process = Runtime.getRuntime().exec(command.toString());
135 StreamReader reader =
new StreamReader(process.getInputStream());
139 return (process.exitValue() == 0);
140 }
catch (Exception e) {
146 private static final String QUERY_COMMAND =
"reg query ";
147 private static final String VALUE_FLAG =
" /v ";
149 private static final String SET_COMMAND =
"reg add ";
150 private static final String TYPE_FLAG =
" /t ";
151 private static final String DATA_FLAG =
" /d ";
152 private static final String FORCE_FLAG =
" /f ";
154 private static final String DELETE_COMMAND =
"reg delete ";
157 static class StreamReader
extends Thread {
158 private InputStream is;
159 private StringWriter sw;
161 StreamReader(InputStream is) {
163 sw =
new StringWriter();
169 while ((c = is.read()) != -1) sw.write(c);
170 }
catch (IOException e) { }
173 String getResult() {
return sw.toString(); }
static boolean deleteKey(String keyName)
static boolean setValue(String keyName, String valueName, String typeExpected, String newValue)
static boolean checkKey(String keyName)
static final String STRING_TYPE
static String getValue(String keyName, String valueName, String typeExpected)
static final String DOUBLEWORD_TYPE
static boolean deleteValue(String keyName, String valueName)