Java??Windows????????????
???????????? ???????[ 2012/12/6 9:57:30 ] ????????
????????????
??????java??windows??????б?????????????????????java??????????????java????Runtime?????????????command?????????????OS??????????????????????????????Ч??????
??????????????????????????????????????????????key?????value??type???????????????С?
????//????????
????add(String location?? String key?? String type?? String value);
????delete(String location?? String key);
????query(String location?? String key);
????//??????????????
????getKey() => ??????key??.
????getValue() => ????key?????value
????getType() => ????key????????????? (REG_SZ?? REG_BINARY?? ??)
???????÷???
????????
public static void main(String[] args) {
try {
RegKeyManager rkm = new RegKeyManager();
// 64λ??????????
// rkm.query("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Tencent\QQ2009"?? "Install");
// 32λ??????????
rkm.query("HKEY_LOCAL_MACHINE\SOFTWARE\Tencent\QQ2009"?? "Install");
System.out.println("KEY: " + rkm.getKey() + " DATA TYPE: " + rkm.getType() + " DATA VALUE: " + rkm.getValue());
// rkm.add("HKEY_LOCAL_MACHINE\SOFTWARE\Tencent\QQ2009"??"TESTING"??"REG_SZ"??"VALUE DATA");
// rkm.delete("HKEY_LOCAL_MACHINE\SOFTWARE\Tencent\QQ2009"??"TESTING");
} catch (Exception e) {
e.printStackTrace();
}
}
???????64λ??????·???????????????????????qq??????·???2????qq????·??????????QQ????·????????д????????????£?????????????????ο?JAVA????????????????·??????????·??????????????????????????????????
package info.itlanguageexpress.java;
import java.io.*;
public class RegKeyManager {
private final String TYPES[] = { "SZ"?? "BINARY"?? "DWORD"?? "QWORD"?? "DWORD_LITTLE_ENDIAN"?? "QWORD_LITTLE_ENDIAN"?? "DWORD_BIG_ENDIAN"?? "EXPAND_SZ"?? "LINK"?? "MULTI_SZ"?? "NONE"?? "RESOURCE_LIST" };
private String type = ""?? value = ""?? key = "";
protected void query(String loc?? String k) throws Exception {
Process p = Runtime.getRuntime().exec("reg QUERY "" + loc + "" /v "" + k + """);
BufferedReader in = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
String out = "";
while ( ( out = in.readLine() ) != null ) {
if (out.matches("(.*)\s+REG_(.*)")) { break; }
}
in.close();
String str[] = out.split(" ");
int b = 0;
for (int a=0; a < str.length; a++) {
if ( str[a].replace(" "?? "").matches("\S+") ) {
switch (b) {
case 0: key = str[a]; break;
case 1: type = str[a]; break;
case 2: value = str[a]; break;
}
b++;
}
}
}
protected String getKey() { return key; }
protected String getType() { return type; }
protected String getValue() { return value; }
protected boolean add(String loc?? String name?? String dType?? String value) throws Exception {
boolean comp = false?? valid = false;
for (int a = 0; a < TYPES.length; a++) {
if (dType.equalsIgnoreCase("REG_" + TYPES[a])) { valid = true; break; }
}
if ( valid ) {
Process p = Runtime.getRuntime().exec("reg ADD "" + loc + "" /v "" + name + "" /t "" + dType + "" /d "" + value + """);
BufferedReader in = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
String out = "";
while ( (out = in.readLine() ) != null ) {
if (out.equalsIgnoreCase("The operation completed successfully.")) { comp = true; }
}
in.close();
}
return comp;
}
protected boolean delete(String loc?? String key) throws Exception {
boolean comp = false;
Process p = Runtime.getRuntime().exec("reg DELETE "" + loc + "" /v "" + key + "" /f");
BufferedReader in = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
String out = "";
while ( ( out = in.readLine() ) != null ) {
if (out.equalsIgnoreCase("The operation completed successfully.")) { comp = true; }
}
in.close();
return comp;
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11