1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class TstRegistry {
private static final int KEY_READ = 0x20019;
private static byte[] toCstr(String str) {
byte[] result = new byte[str.length() + 1];
for (int i = 0; i < str.length(); i++) {
result[i] = (byte) str.charAt(i);
}
result[str.length()] = 0;
return result;
}
public static void main(String[] args) {
try {
Preferences systemRoot = Preferences.systemRoot();
Preferences userRoot = Preferences.userRoot();
final Class clz = userRoot.getClass();
final Method openKey = clz.getDeclaredMethod("openKey", byte[].class, int.class, int.class);
openKey.setAccessible(true);
final Method winRegQueryValue = clz.getDeclaredMethod("WindowsRegQueryValueEx", int.class, byte[].class);
winRegQueryValue.setAccessible(true);
final Method closeKey = clz.getDeclaredMethod("closeKey", int.class);
closeKey.setAccessible(true);
byte[] valb = null;
String vals = null;
String key = null;
Integer handle = -1;
key = "SOFTWARE\\Classes\\Applications\\WINWORD.EXE\\shell\\edit\\command";
handle = (Integer) openKey.invoke(systemRoot, toCstr(key), KEY_READ, KEY_READ);
valb = (byte[]) winRegQueryValue.invoke(systemRoot, handle, toCstr(""));
vals = (valb != null ? new String(valb).trim() : null);
System.out.println("Path = " + vals);
closeKey.invoke(Preferences.systemRoot(), handle);
} catch(Exception e) {
e.printStackTrace();
}
}
} |
Partager